Wednesday, April 5, 2006

AA Dekhe Zara... Test your C Skillssss

An Elite Questions on the concepts of C that will keep you On the Rockssss

1. state the output
#include
int a = 20;
void main()
{
fun1();
printf(" ");
fun1();
printf(" ");
fun1();
printf(" ");
}

fun1()
{
static int b = 10;
b++;
printf("%d", b++);
b=12;
printf(" ");
printf("%d", b++);
}

A 10 12 10 12 10 12
B 11 12 11 12 11 12
C 11 12 14 12 14 12
D Error "static variable re-assignment"

2. State o/p
#include
int main()
{ 123456789
printf("%d",-16["WHAT A PLAYER WHAT A PLAYER SLUMDOG!!!"]);
return 0;
}
A. Error
B. GARBAGE
c. 65
D.none of the above

3. state o/p
main()
{
char x = 0x8A;
unsigned int y = x;
printf("%d\n", y);
}
A -118
B 138
C 118
D Unpredictable

4. state o/p
#include
#include
int main()
{
printf("%c\n", 'mujhe khoon do main tumhe pani duungah' -3);
return 0;
}
A warning,Outputs: -h
B error
c warning, Outputs: e
d warning, Outputs: n
e warning, Outputs: (ascii value of h)

5. #include

int main()
{
struct {
int i;
char j;
long k;
}b;

&b.k - &b;
}
Is this error ?
A Yes
B No
Give reasons

6. O/p

#include
int main()
{
int x=10;
printf("%d",++x+x++a)
printf("this world is good and ");
else printf("not so bad after all ");
if(7.7>b)
printf("this world is good ");
else printf("not so bad after all");
}

A not so bad after all not so bad after all
B this world is good and this world is good
C this world is good and not so bad after all
D not so bad after all this world is good

10. Which of the following is the correct output for the program given below?
main()
{
int a=500, b=100, c;
if(!a>=400)
b=300; c=200;
printf("b=%d c=%d", b,c);
}

1.b=300 c=200
2.b=100 c=garbage
3.b=300 c=garbage
4.b=100 c=200

11. In the program given below, point out the error, if any, in the while loop?
main() {
int i=1;
while()
{ printf("%d",i++);
if(i>10) break; }
}

1.the condtion in the while loop is must
2.There should be atleast a semicolon in the while()
3.The while loop should be replaced by the for loop
4.No Error

12. Which of the following is the correct output for the program given below?
main() {
int x=10, y=20;
if(!!!!x2&&x)
printf("x=%d", x);
else
printf("y=%d",y);
}

1.Y=20
2.X=10
3.X=-10
4.X=0
5. Error

13. Which of the following statements are correct about the C program given below?
main() {
int i, x=10, y=100%90;
for(i=1;i<=10;i++) if(x!=y) printf("x=%d y=%d", x,y); } 1.The printf() function is called 10 times 2.The program will produce the output x=10 y=10 3.The program will not produce any output 4.the printf() function is called infinite times 14.Predict o/p void myFunc (int x) { if (x > 0)
myFunc(--x);
printf("%d, ", x);
}
int main()
{
myFunc(5);
return 0;
}

Choice 1: 1, 2, 3, 4, 5, 5,
Choice 2: 4, 3, 2, 1, 0, 0,
Choice 3: 5, 4, 3, 2, 1, 0,
Choice 4: 0, 0, 1, 2, 3, 4,
Choice 5: 0, 1, 2, 3, 4, 5,

15.O/p
x = 3, counter = 0;
while ((x-1))
{
++counter;
x--;
}
printf("%d",x);

Choice 1: 0
Choice 2: 1
Choice 3: 2
Choice 4: 3
Choice 5: 4

16. #include
int i;
int increment( int *i )
{
return ++i;
}

int main()
{
for( i = 0; i < i="%d\n" i="9." i="10." i="11." i =" 4;" i ="=" i ="=" i =" %d\n" i =" 5" i =" 8" i =" 9" i =" 10" i =" 18" x =" 0;" x="%d\n" x="0" x="1" x="4" x="5" x="6" buffer = "0123456789" ptr =" buffer;" a="10,b=" x="1,y=" a =" 1" a =" 0;" q =" &a;" p =" &q;" p="**p+1;" x="**p-a;" x="=" ptr="(char*)arr;" ch =" 0" y =" 12;" x =" -2;">y)
printf (" x is greater");
else
printf (" y is greater");
return 0;
}

1) y is greater
2) x is greater
3) compiler warning with o/p- y is greater
4) compiler warning with o/p- x is greater

7)O/p of the program
# include "stdio.h"
int main() {extern int p;
printf("%d",p);return 0;}
int p;
1) error extern int is declaration not a defnition’
2) 0
3) Garbage value
4) None of the above


8)o/p of the following program
# include "stdio.h"
int main()
{
int a=20;
int c;

(a==20)?b=30:c=20;
printf("%d",b);
return 0;
}
1) 30
2) 3
3) Error-invalid Lvalue in assignment
4) Garbage value

9)# include "stdio.h"
int main()
{
int a=30, b=40, x;
x=(a!=10) && (b==50);

printf("%d",x);
return 0;
}
1) 0
2) 1
3) Garbage value
4) None of the above

10. O/p of the following program
# include "stdio.h"
int main()
{
int a=-3,b=2,c=0,k=1;
if((++a&&++b)++k)
printf("%d %d %d",a,b,k);
return 0;
}
1) -2 -3 1
2) -2 3 2
3) -2 3 1
4) -1 3 0

11) o/p of the program
# include "stdio.h"
int main()
{
int x[] = { 1, 4, 8, 5, 1, 4 };
int *ptr, y;
ptr=&x;
y = *ptr -x[2];
printf("%d",y);
return 0;
}
1) 0
2) -7
3) 4
4) 1
12) O/P assume a 32 bit compiler
# include "stdio.h"
int main()
{
int x[6] = { 1, 4, 8, 5, 1, 4 };
int( *ptr)[6]= x;
int y=(*ptr)[2]+1;
printf("%d %d",y,sizeof(*ptr));
return 0;
}
1) 9 4
2) 5 4
3) 9 24
4) 5 24

13) O/P assume a 32 bit compiler
# include "stdio.h"
int main()
{
int x[6] = { 1, 4, 8, 5, 1, 4 };
int( *ptr)[6]= x;
++(*ptr)[2];
int y=x[2]+1;
printf("%d %d",y,sizeof(*ptr,ptr));
return 0;
}
1) 9 4
2) 8 24
3) 10 4
4) 9 24
14) A float occupies 4 bytes.If the hexadecimal equivalent of each of these bytes is A,B,C,D when this float is stored in the memory these bytes get stored in the order
1) ABCD
2) DCBA
3) 0XABCD
4) 0XDCBA
15) Is this a valid delaration
int ((*p)[10])(int , char) ;


16) O/p of the following program
# include "stdio.h"
int main()
{
int arr[5]={2,4,6,8,10};
int *ptr;
ptr=&arr[2];
printf("%d \n",ptr[-2]);
return 0;
}

1) 4
2) 2
3) Garbage value
4) Invalid assignment

17) O/p pf the following code
# include "stdio.h"
int main()
{
char arr[5];
strcpy(arr,"\0");
if (arr==NULL)
printf("arr is null \n");
else
printf("arr is not null \n");
return 0;
}

1) Garbage value
2) Error
3) arr is null
4) arr is not null

19)O/p of the following program
# include "stdio.h"
double i=0.0;
int main()
{
switch(i)
{
case 0.0:
printf("0.0");
case 1.0:
printf("1.0");
break;
default:
printf("Default");
}
return 0; }

1) 0.0
2) Error
3) 1.0
4) Garbage value

20. O/p pf the following program

# include "stdio.h"
double i=0.0;
int main()
{
char arr[8]={'S','A','V','R','I','Y','A'};
char *p;
p=(char *)(arr+2)[3];
printf("%c",p);
return 0;
}
1) Error
2) Garbage Value
3) V
4) Y

No comments: