Monday, June 8, 2009

What is the output of following programme ?

main()
{
int a=2,*f1,*f2;
f1=f2=&a;
*f2+=*f2+=a+=2.5;
*f1+=*f1+=a+=2.5;
printf("\n%d %d %d",a,*f1,*f2);
}

Choice
a) 18,18,18
b) 10,10,10
c) 72,72,72
d) 64,64,64
e) 26,26,26

Monday, June 1, 2009

Whatz the output

void main()
{
int i = abc(10);
printf("%d\n",--i);
}

int abc(int i)
{
return(i++);
}

Choice
a) 10
b) 11
c) 9
d) 0

Wednesday, May 27, 2009

What is the output of following programme ?

int main()
{
int x=10;
printf("%d",++x+x++<x+++x++);
return 0;
}

a. Error
b. 1
c. 24
d. 0
e. 46

Tuesday, May 26, 2009

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"

Tuesday, May 19, 2009

You have a program containing the following statements:

#define ARRAYSIZE 20
char str[ARRAYSIZE]="Test string";
strcat(str, 'z');

When you run the program, it produces a segmentation fault.

Referring to the above scenario, how do you resolve the problem?
Choice a : Use malloc to dynamically allocate memory, rather than using a fixed array.
Choice b : Change 'z' to 'z\0'
Choice c : Change ARRAYSIZE to 21.
Choice d : Change 'z' to "z"
Choice e : Change strcat to strncat and specify a size of 1.