Tuesday, May 11, 2010

Structure Comparison

) int main()
{
struct emp
{
char name[20];
int empno;

};

struct emp e1 = {"harrypotter", 1311};

struct emp e2 = e1;

if (e1==e2)
printf ("e1 and e2 are same");
else
printf ("e1 and e2 are different");

}

Choice:
a)e1 and e2 are same
b)e1 and e2 are different
c)Error
d)Segmentation fault

Monday, February 15, 2010

What is the output of following program?

2) void squared(void *nbr)
{
*nbr *= *nbr;
}

int main()
{
int a = 2;
squared((void *)a);
return 0;
}

Choice:
a)Error
b)4
c)4 with warning
d)2
e)Segmentation Fault

C Preprocessor Question

#define PRINT printout

int main()
{
printf("PRINT");
}

Choice:
a)error
b)PRINT
c)printout
d)no output

Wednesday, February 10, 2010

What does the operation shown below produce?

11 ^ 5

a) 1
b) 6
c) 8
d) 14
e) 15

Which of the following is the correct way to increment the variable "ptr"?

a) ptr = ptr + sizeof(myStruct); [Ans]
b) ++(int*)ptr;
c) ptr = ptr + sizeof(myArray);
d) increment(ptr);
e) ptr = ptr + sizeof(ptr);