Questions on C :: Part-I
Posted by Subash | 8:30 PM
[12] Comments
- What is the output of the program given below #include
main()
{
char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
} - What is the output of the following program #include
main()
{
int i=0;
fork();
printf("%d",i++);
fork();
printf("%d",i++);
fork();
wait();
} - What is the memory allocated by the following definition ?
int (*x)[10]; - What is the memory allocated by the following definition ?
int (*x)(); - In the following program segment #include
main()
{
int a=2;
int b=9;
int c=1;
while(b)
{
if(odd(b))
c=c*a;
a=a*a;
b=b/2;
}
printf("%d\n",c);
}
How many times is c=c*a calculated? - In the program segment in question 5 what is the value of a at the end of the while loop?
- What is the output for the program given below
typedef enum grade{GOOD,BAD,WORST,}BAD;
main()
{
BAD g1;
g1=1;
printf("%d",g1);
} - Give the output for the following program. #define STYLE1 char
main()
{
typedef char STYLE2;
STYLE1 x;
STYLE2 y;
clrscr();
x=255;
y=255;
printf("%d %d\n",x,y);
} - Give the output for the following program segment.
#ifdef TRUE
int I=0;
#endif
main()
{
int j=0;
printf("%d %d\n",i,j);
} - In the following program #include
main()
{
char *pDestn,*pSource="I Love You Daddy";
pDestn=malloc(strlen(pSource));
strcpy(pDestn,pSource);
printf("%s",pDestn);
free(pDestn);
}
(a)Free() fails
(b)Strcpy() fails
(c)prints I love You Daddy
(d)error - What is the output for the following program
#include
main()
{
char a[5][5],flag;
a[0][0]='A';
flag=((a==*a)&&(*a==a[0]));
printf("%d\n",flag);
} - Find the output of the following program
int *p,*q;
p=(int *)1000;
q=(int *)2000;
printf("%d",(q-p));Ans: 500
- What does the statement int(*x[])() indicate?
- How are parameters passed to the main function?
- What does the file stdio.h contain?
a) functin definition
b) function decleration
c) both func. defn & func. decleration. - sscanf is used for ?
- What does the statement strcat(S2,S1) do?
- Write a program to insert a node in a sorted linked list.
- Write a program to implement the Fibonacci series.
- Write a program to concatenate two circular linked lists into a single circular list.
9:23 PM
You should also write answers alongwith explanations.
6:55 PM
Ans 1: -128
don't know Ans 2.....please Ans 2
9:23 PM
Ans 3: 4 bytes--- size of a pointer to "array of 10"
Ans 4: 4bytes--- size of a pointer to
"function of type int(void)"
Ans 5: 2 times-- when b=9 and when b=1
Ans 6: a=(((a^2)^2)^2)^2=2^16=65536
Ans 7: [:(]
Ans 8:-1-1
Ans 9:0 0
12:23 AM
the questions are seriously very good
10:35 AM
please write answer 2 verify the ans...........
mukhi
12:09 PM
one can always run the program to find out the answers. It's a good idea to verify our answers even.
10:38 AM
Answer 5 : Its just 1 . Once b = 4 , it can never enter the if loop again. So b is never = 1.
2:12 PM
ans 3:its an array of 10 pointers,so its size is 20 bytes.
2:16 PM
ans 6:2 power 16
2:21 PM
ans 7:its an error,because of redeclaration of BAD(as enum variable as well as enum constant)
2:02 PM
Ans 2: 0101010101010101
(As outputted by GCC)
10:13 PM
ans of 5:
if has no braces...so ans is 4