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);

What number will z in the sample code contain?

int z,x=5,y=-10,a=4,b=2;
z = x++ - --y * b / a;

a) 5
b) 6
c) 10
d) 11
e) 12

Understanding Stack and Queue

The five items: A, B, C, D and E are pushed in a stack,one after the other starting from A. The stack is popped four times and each element is inserted in a queue. Then two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack.
The popped item is


a) A
b) B
c) C
d) D

fputs function is used to ?

i. write characters to a file
ii. takes 2 parameters
iii. returns a character
iv. requires a file pointer

a) all are true
b) all are false
c) only i and ii are true
d) only i,ii and iv are true


What is the output of this program?

main()
{
struct
{
int i;
}xyz;
(*xyz)->i=10;
printf("%d",xyz.i);
}

a) program will not compile
b) 10
c) god only knows
d) address of i

Monday, February 8, 2010

What is the output of following programme ?

# include
# define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
}

a) 10..10
b) 10..50
c) Error
d) 0

What does the following program print?

int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

main()
{
int i;
for(i = 0; i < 3; i++)
 printf("%d%d%d", a[i][2-i], *a[i], *(*(a+i)+i));
}

 a) 3 1 1
     5 4 5
     7 7 9
 b) 7 1 1
    5 4 5
    3 7 9
 c) 3 1 1
    5 4 7
    7 7 9
 d) 3 5 7
    1 4 7
    1 7 9

The output of printf("%u", -1) is

a) -1
b) Minimum int value
c) Maximum int value
d) Error message

The printf() function retunes which value when an error occurs?

a) Positive value
b) Zero
c) Negative value
d) None of these