Write down the output of the following programs
1) void main()
{
int x = 10, y = 3, z = 2;
if(x – (++y * ++z – –z))
printf(”Hello”);
else
printf(”Hai”);
}
a) compilation error b)runtime error c)Hello d)Hai
2) void main()
{
unsigned x = 1;
printf(”%u %u %u\n”, –x, x, x–);
}
a) 1 0 –1 b) 1 1 1 c) 65535 0 1 d) -1 0 1
3) void main()
{
float x = 10.5;
switch(x)
{
case 10.5:
printf(”Good”);
break;
case 11.6:
printf(”Bad”);
break;
default:
printf(”default”);
break;
x++;
}
}
a) compilation error b) runtime error c) Good d) default
4) void main()
{
int x, y = -2;
x = y == -1 ? -3 : -2;
printf(”%d”,x);
}
a) compilation error b) 3 c) –2 d) -3
5) void main()
{
printf(”%d”, strcmp(”a”, “d”));
}
a) –3 b) 1 c) 0 d) -1
6) void main()
{
int *ptrI, i = 10;
float *ptrF, f = 3.14;
char *ptrC, c = ‘a’;
printf(”%d %d %d”, sizeof(ptrI), sizeof(ptrF), sizeof(ptrC));
}
a) compilation error b) 2 2 2 c) 10 3.14 a d) 2 4 1
7) void main()
{
int i;
for(i = 0; i <>
{
for(i = 0; i <>
;
printf(”%d “,i);
}
}
a) infinite loop b) 10 c) 5 d) 0
void main()
{
char str[3] = {2};
int i;
for(i = 0; i <>
printf(”%d “,str[i]);
}
a) compilation error b) 2 0 0 c) garbagevalue d) 0 0 0
9) void main()
{
char *str;
str = “goodmorning”;
printf(”%s”,–(++str));
}
a) compilation error b) runtime error c) goodmorning d) oodmorning
10) void main()
{
int x;
struct st
{
int no;
char name[30];
}a;
a.no = 100;
printf(”%d”,a);
}
a) compilation error b) 100 c) garbagevalue d) null
11) void main()
{
union un
{
int no;
char name[30];
}u;
u.no = 50;
strcpy(u.name, “Raj”);
printf(”%d %s”, u.no, u.name);
}
a) compilation error b) garbagevalue Raj c) 50 Raj d) Raj Raj
12) void main()
{
int arr[] = {10, 20, 30, 40};
printf(”%d”, 2[arr]);
}
a) compilation error b) runtime error c) 30 d) 40
13) void main()
{
enum col{violet, indigo, blue, green, yellow, orange, red};
printf(”%d”, ++indigo);
}
a) compilation error b) 1 c) 2 d) 3
14) void main()
{
int arr[3][4] = {
{1, 2},
{3, 4}
};
int *ptr = &arr[0][0], i, j;
for(i = 0; i <>
for(j = 0; j <>
_____________________
}
What should be the statement in the blank to print all the elements in the array
a) printf(”%d “, *(ptr + i * 4 + j)); b) printf(”%d “, *(ptr + i + j));
c) printf(”%d “, *(ptr + i * 3 + j)); d) printf(”%d “, *(ptr + j * 4 + i));
15)
void main()
{
char a['a'] = {’a', ‘b’, ‘c’, ‘d’};
printf(”%c”, a[2]);
}
a) compilation error b) a c) b d) c
16) int b = 20;
int fun()
{
int b = 5;
static int a = 10;
b++;
return(a++);
}
void main()
{
int y;
int fun();
fun();
fun();
y = fun();
printf(”%d %d”, y, b);
}
a) 12 20 b) 10 20 c) 12 7 d)10 7
17) void main()
{
int a = 10, b = 3;
printf(”%f”, a / b);
}
a) compilation error b) runtime error c) 3.333333 d) 3
18) void main()
{
int a = 512;
printf(”%d “, a <<>
}
a) compilation error b) 511 c) 512 d) 1024
19) void main()
{
char str[50] = “Hello”;
int i = 0;
while(str[i] != ‘\0′)
{
if(str[i++] == ‘l’)
continue;
printf(”%c “, str[i]);
}
}
a) H e l l o b) e l c) H e o d) l l
20) void main()
{
char str[] = {’g', ‘o’, ‘o’, ‘d’, ‘\\’, ‘0′, ‘m’, ‘o’, ‘r’, ‘\0′, ‘n’, ‘i’, ‘n’, ‘g’};
puts(str);
}
a) compilation error b) goodmor c) good\0mor d) goodmorning
21) void main()
{
int x[] = {10, 20, 30, 40, 50};
int *ptr = &x[0];
printf(”%d”, (ptr + 3) – (ptr + 1));
}
a) compilation error b) 2 c) 4 d) 20
22) void main()
{
char ch = 65;
switch(ch)
{
case ‘A’:
printf(”1″);
case ‘B’:
printf(”2″);
ch++;
case ‘C’:
printf(”3″);
ch++;
default:
printf(”10″);
break;
}
printf(”%c”, ch);
}
a) compilation error b) A B C 10 C c) 1 2 3 4 10 C d) 1 C
23) void main()
{
unsigned int num = 10;
printf(”%d”, num & -1);
}
a) compilation error b) 0 c) 10 d) 9
24) void main()
{
int i;
for(i = 0; i <>
{
if(i == 2)
goto label;
printf(”%d “, i);
label: i = 4;
}
}
a) compilation error b) infinite loop c) 0 d) 0 1 4
25) void main()
{
char name1[50], name2[50];
scanf(”%s %s”, name1, name2);
printf(”%s %s”, name1, name2);
}
If the name entered are:
suresh kumar
manoj sharma
Output is:
a) compilation error b) suresh c) suresh kumar d) suresh kumar manoj sharma
Answer Key
1) d 2) c 3) a 4) d 5) a 6) b 7) b b 9) a 10) b 11) b
12) c 13) a 14) a 15) d 16) a 17) b 18) d 19) b 20) c 21) b 22) c
No comments:
Post a Comment