0% found this document useful (0 votes)
14 views8 pages

C Output Questions-25

The document contains a series of C programming questions focused on identifying errors and outputs from various code snippets. Each question presents a piece of code followed by multiple-choice answers. The questions cover a range of topics including variable manipulation, function behavior, control structures, and memory management.

Uploaded by

dgpguru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

C Output Questions-25

The document contains a series of C programming questions focused on identifying errors and outputs from various code snippets. Each question presents a piece of code followed by multiple-choice answers. The questions cover a range of topics including variable manipulation, function behavior, control structures, and memory management.

Uploaded by

dgpguru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

C Output Questions

1. Find Error/Output in follwing code:


void main ()
{
int x = 128;
printf ("n%d", 1 + x++);
}
a) 128
b) 129
c) 130
d) 131
2.Find Error/Output in follwing code:
#include <stdio.h>
int tmp=20;
main( ) {
printf("%d ",tmp);
func( );
printf("%d ",tmp);
}
func() {
static int tmp=10;
printf("%d ",tmp);
}
a) 20 10 10
b) 20 10 20
c) 20 20 20
d) 10 10 10
3.Find Error/Output in follwing code:
main() {
int a = 10;
if ((fork ( ) == 0))
a++;
printf ("%dn", a );
}
a) 10 and 11
b) 10
c) 11
d) 11 and 11
4.Find Error/Output in follwing code:
#include <stdio.h>
main( ) {
int i;
for ( i=0; i<5; i++ ) {
int i = 10;
printf ( " %d", i );
i++;
}
return 0;
}

a) 10 11 12 13 14
b) 10 10 10 10 10
c) 01234
d) Compilation error
5.Find Error/Output in follwing code:
struct
{
int si;
double d;
float cp;
} s;
void
main ()
{
printf ("%d, %d, %d", sizeof (s.si), sizeof (s.d), sizeof (s.cp));
}

a) 6, 10, 8
b) 4, 8, 4
c) 2, 4, 4
d) 2, 8, 8

6. Find Error/Output in follwing code:


int main ()
{
int a, b;
a = b = 4;
b = a++;
printf ("%d %d %d %d", a++, --b, ++a, b--);
}
a) 5 3 7 3
b) 5 4 5 3
c) 6 2 6 4
d) Syntax Error

7.Find Error/Output in follwing code:


int main ()
{
int a[4] = { 25, 16 };
printf ("%d %d", a[0] & a[1], a[1] | a[2]);
}

a) Syntax error because of invalid operator symbol


b) 25 16
c) 16 16
d) Syntax error because of invalid array initialization

8. Find Error/Output in follwing code:


int main ()
{
static int num = 8;
printf ("%d", num = num - 2);
if (num != 0)
main ();
}

a) 8642
b) Infinite output
c) Invalid because main function can't call itself.
d) 6420
9.Find Error/Output in follwing code:
How many times "Placement Question" will print.
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("Placement Question");
}
return 0;
}

a) Infinite Time
b) 11 Times
c) 0 Time
d) 10 Times

10. Find Error/Output in follwing code:


int main()
{
printf("%d%d%d", sizeof(3.14f), sizeof(3.14l));

a) 4160
b) 844
c) 3284
d) None of the above
11. Find Error/Output in follwing code:
int main()
{
int a = 10, b = 25;
a = b++ + a++;
b = ++b + ++a;
printf("%d %d n", a, b);
}
a) 36 64
b) 35 62
c) 36 63
d) 30 28
12.Find Error/Output in follwing code:
int main()
{
char arr[7]="Network";
printf("%s", arr);
return 0;
}
a) Network
b) N
c) Garbage value
d) Compilation error
13.Find Error/Output in follwing code:
int main()
{
int x = 7538;
printf("%d %dn", x % 100, x / 10);
}
a) 38 753
b) 75 538
c) 538 38
d) 0 753
14.Find Error/Output in follwing code:
int main ()
{
int x = 20, y = 35;
x = y++ + x++;
y = ++y + ++x;
printf ("%d %d n", x, y);
}
a) 55 92
b) 56 93
c) 57 94
d) None of the above

15.Find Error/Output in follwing code:


void fn()
{
static int i = 10;
printf("%d ", ++i);
}
int main()
{
fn();
fn();
}
a) 10 10
b) 11 11
c) 11 12
d) 12 12
16.Find Error/Output in follwing code:
int main ()
{
int x = 24, y = 39, z = 45;
z = x + y;
y = z - y;
x = z - y;
printf ("n%d %d %d", x, y, z);
}
a) 24 39 63
b) 39 24 63
c) 24 39 45
d) 39 24 45
17.Find Error/Output in follwing code:
int main ()
{
int check = 2;
switch (check)
{
case 1:
printf ("D.W.Steyn");
case 2:
printf (" M.G.Johnson");
case 3:
printf (" Mohammad Asif");
default:
printf (" M.Muralidaran");
}
return 0;
}

a) D.W.Steyn
b) D.W.Steyn M.G.Johnson
c) M.G.Johnson
d) M.G.Johnson Mohammad Asif M.Muralidaran
18.Find Error/Output in follwing code:
int main ()
{
int a = 5;
float b;
printf ("%d", sizeof (++a + b));
printf (" %d", a);
return 0;
}
a) 6 5
b) 5 6
c) 4 5
d) 5 4
19.Find Error/Output in follwing code:
int main() {
int m = -10, n = 20;
n = (m < 0) ? 0 : 1;
printf("%d %d", m, n);
}
a) -10 0
b) 10 20
c) 20 -10
d) 0 1
20.Find Error/Output in follwing code:
int main() {
int i=0;
for(;;)
printf("%d",i);
return 0;
}
a) 0 times
b) Infinite times
c) 10 times
d) 1 times
21.Find Error/Output in follwing code:
int main() {
char c = 'f';
switch (c) {
default: printf("unknown colour ");
case 'r': case 'R': printf("Red ");
case 'g': case 'G': printf("Green "); break;
case 'b': case 'B': printf("Blue");
}}
a) Red Green Blue
b) Error
c) Green unknown colour Red
d) unknown colour Red Green
22. Find Error/Output in follwing code:
int main() {
int a = 100, b = 74;
if (a++ > 100 && b++ > 200)
printf("High values with a = %d b = %dn", a, b);
if (a++ < 100 || b++ < 200)
printf("Low values with a = %d b = %dn", a, b);
}
a) Low values with a = 100 b = 74
b) Low values with a = 101 b = 73
c) Low values with a = 102 b = 75
d) Low values with a = 104 b = 75
23. Find Error/Output in follwing code:
int main() {
char p[] = "%dn";
p[1] = 'c';
printf(p, 65);
int k=40, *a;
a = &k;
(*a)++; k++;
printf("n k=%d",k);
}
a) c k=40
b) b k=44
c) A k=42
d) a k=40
24.Find Error/Output in follwing code:
int main() {
int x = 1;
while(x = 0)
printf("hello");
}
a) hello
b) No output
c) Infinite time hello display
d) Error in code
25.Find Error/Output in follwing code:
int main() {
int x = 0, y = 0;
if(x > 0)
if(y > 0)
printf("True");
else
printf("False");
}
a) No Output
b) True
c) False
d) Error because of dangling else problem
26.Find Error/Output in follwing code:
main() {
int i = 2, *j;
j = &i;
printf("%d", i**j*i+*j);
}
a) Syntax error due to Invalid expression in printf
b) Print junk value
c) 16
d) 10
27.Find Error/Output in follwing code:
int main() {
int x,y,z;
x = '1'-'0'; /* line-1 */
y = 'a'-'b'; /* line-2 */
z = x + y;
printf("%d",z);
}
a) 0
b) Error because of incorrect line-1 only.
c) Error because of incorrect line-1 and line-2.
d) Error because of incorrect line-2 only.
28.Find Error/Output in follwing code:
void fn() {
int a = 10;
static int b = 20;
printf("a = %d b = %d", ++a, ++b);
}
int main() {
fn();
fn();
return 0;
}
a = 11 b = 21 a = 11 b = 22
a = 11 b = 21 a = 11 b = 22
a = 11 b = 21 a = 11 b = 22
a = 11 b = 21 a = 11 b = 22
Find Error/Output in follwing code:
void main ( )
{
char *P = "ayqm" ;
char c;
c = ++*p ;
printf ("%c", c);
}
a
0x56FA
m
y

29.Find Error/Output in follwing code:


void main()
{
int x=10,*y,**z;
y=&x;
z=&y;
printf(\"%d%d%d\",*y,**z,*(*z));
}
a) 101010
b) 100xaa54f10
c) Run time error
d) No Output
30.Find Error/Output in follwing code:
void main()
{
int a = 1, b=2, c=3;
char d = 0;
if(a,b,c,d)
{
printf("EXAM");
}
}
a) No Output and No Error
b) EXAM
c) Run time error
d) Compile time error

31.Find Error/Output in follwing code:


void main()
{
int a = 1, b=2, c=3;
if(a,b,c)
{
printf("EXAM");
}}
EXAM
No Output
Run time error
None of the above
32.Find Error/Output in follwing code:
void main()
{
printf("%d", printf("computer science"));
}
a) computer science16
b) 16computer science
c) computer science
d) computer science18

You might also like