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

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

Sunday, January 10, 2010

What does the following program print?

#include

void main()
{

static struct S1
{
char c[4], *s;
} s1 = {"abc", "def"};

printf("%c %c\n", s1.c[0], *s1.s);
printf("%s %s", s1.c, s1.s);
}

a) Compiler error

b) a def
    abc def

c) a d
    abc def

d) a d
    a def


What is the output of following program?

#include
int main()
{
printf("%c\n", '1' + 1);
return EXIT_SUCCESS;
}

a) ASCII value of '1' is required to find out the answer
b) 2
c) 50
d) Syntax Error

#include
void func()
{
int x = 0;
static int y = 0;
x++; y++;
printf( "%d -- %d\n", x, y );
}

int main()
{
func();
func();
return 0;
}

What will the code above print when it is executed?

a) 1 -- 1
1 -- 1
b) 1 -- 1
2 -- 1
c) 1 -- 1
2 -- 2
d) 1 -- 0
1 -- 0
e) 1 -- 1
1 -- 2

Which one of the following statements could replace the ???? in the code above to cause the string 1-2-3-10-5- to be printed when the code is executed?

int x[] = {1, 2, 3, 4, 5};
int u;
int *ptr = x;
????
for( u = 0; u < 5; u++ ) { printf("%d-", x[u]); } printf( "\n" ); a) *ptr + 3 = 10; b) *ptr[ 3 ] = 10; c) *(ptr + 3) = 10; d) (*ptr)[ 3 ] = 10; e) *(ptr[ 3 ]) = 10;

With what do you replace the ???? to make the function shown below return the correct answer?

long factorial (long x)
{
????
return x * factorial(x - 1);
}

a) if (x == 0) return 0;
b) return 1;
c) if (x >= 2) return 2;
d) if (x == 0) return 1;
e) if (x <= 1) return 1;

How many bytes are allocated by the definition below?

char txt [20] = "Hello world!\0";

a) 11 bytes
b) 12 bytes
c) 13 bytes
d) 20 bytes
e) 21 bytes

In terms of code generation, how do the two definitions of buf, both presented above, differ?

char buf [] = "Hello world!";
char * buf = "Hello world!";

a) The first definition certainly allows the contents of buf to be safely modified at runtime; the second definition does not
b) The first definition is not suitable for usage as an argument to a function call; the second definition is
c) The first definition is not legal because it does not indicate the size of the array to be allocated; the second definition is legal
d) They do not differ -- they are functionally equivalent
e) The first definition does not allocate enough space for a terminating NUL-character, nor does it append one; the second definition does

Which one of the following will declare a pointer to an integer at address 0x200 in memory?

a) int *x;
*x = 0x200;
b) int *x = &0x200;
c) int *x = *0x200;
d) int *x = 0x200;
e) int *x( &0x200 );


What string does ptr point to in the sample code below?

char *ptr;
char myString[] = "abcdefg";
ptr = myString;
ptr += 5;

a) fg
b) efg
c) defg
d) cdefg
e) None of the above

What value will x contain when the sample code below is executed?

int x = 3;
if( x == 2 );
x = 0;
if( x == 3 )
x++;
else x += 2;

a) 1
b) 2
c) 3
d) 4
e) 5