D) Program 2 Has Syntax Error, Program 1 Is Not

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

1. What is the difference between the following 2 codes?

#include <stdio.h> //Program 1


int main()
{
int d, a = 1, b = 2;
d = a++ + ++b;
printf("%d %d %d", d, a, b);
}
#include <stdio.h> //Program 2
int main()
{
int d, a = 1, b = 2;
d = a++ +++b;
printf("%d %d %d", d, a, b);
}

a) No difference as space doesnt make any difference, values of a, b, d are


same in both the case
b) Space does make a difference, values of a, b, d are different
c) Program 1 has syntax error, program 2 is not
d) Program 2 has syntax error, program 1 is not

2. What is the output of this C code?


` #include <stdio.h>
int main()
{
int a = 1, b = 1, c;
c = a++ + b;
printf("%d, %d", a, b);
}
a) a = 1, b = 1
b) a = 2, b = 1
c) a = 1, b = 2
d) a = 2, b = 2

3. What is the output of this C code?


#include <stdio.h>
int main()
{
int a = 10, b = 10;
if (a = 5)
b--;
printf("%d, %d", a, b--);
}
a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9
d) a = 5, b = 8

4. What is the output of the C statement 7.5 % 3?


a) 1 b) 1.5 c) error d) no output

5. What is the output of this C code?


void main()
{
int a = 500, b = 100,c;
if(!a>=400)
b = 300;
c = 200;
printf ("b = %d c = %d",b,c);
}

(a) 100, 200 (b) 300, 200 (c) 100, 0 (d) 300, 0

6. What is the output of this C code?


void main()
{
int c = 0, d = 5, e = 10, a;
a = c> 1 ? d > 1 || e > 1 ? 100:200:300;
printf ("a = %d", a);
}

(a) 100 (b) 200 (c) 300 (d) None of the above

7. What is the output of this C code?


void main()
{
printf ("bytes occupied by 7 = %d", sizeof ( 7 ) ) ;
printf ("bytes occupied by 7 =%d", sizeof ( 7 ) ) ;
printf ("bytes occupied by 7.0 = %d", sizeof (7.0));
}

(a) 1 2 4 (b) 1 2 8 (c) 2 2 4 (d) 2 2 8


8. What is the output of this C code?
void main()
{
printf ("%d %f \n", 4,4);
printf ("%d%f\n", 4.0,4.0);
}

(a) 4 0.000000
0 4.000000
(b) 4 4.000000
0 4.000000
(c) 4 4.000000
4 4.000000
(d)4 0.000000
4 4.000000

9. What is the output of this C code?


void main()
{
int i = 3, a = 4, n;
float t = 4.2;
n = a*a/i + i/2*t + 2 + t;
printf ("n = %d", n ) ;
}

(a) 16 (b) 15 (c) 14 (d) 17

10. Which bitwise operator is suitable for checking whether a particular bit is
on or off?
A B
&& operator & operator
. .
C D
|| operator ! operator
. .

11. What is the output of this C code?


#include<stdio.h>
int main()
{
int k;
k = (1,2,3,4,5);
printf("%d\n", k);
return 0;
}
a) 2 b) 5 c) 1 d) 4

12. What is the output of this C code?


#include<stdio.h>
int main()
{
int k, num = 100;
k = (num > 50 ? (num <= 10 ? 100 : 200): 500);
printf("%d\n", num);
return 0;
}

a) 500 b) 200 c) 100 d) 300

13. What is the output of this C code?


#include<stdio.h>
int main()
{
int x=10;
printf("%d, %d, %d\n", x <= 10, x = 40, x >= 10);
return 0;
}

a) 1, 40, 1 b) 0, 1, 1 c) 1, 1, 1 d) 0, 40, 1

14. How many times "IndiaBIX" is get printed?


#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("IndiaBIX");
}
return 0;
}

a B
Infinite times 11 times
. .
C D
0 times 10 times
. .

15. Which of the following cannot be checked in a switch-case statement?


A B
Character Integer
. .
C D
Float enum
. .

16. What is the size of an int data type?


a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined

17. Which of the following statement is used to take the control to the
beginning of the loop?
a) break b) continue c)exit d) none of these

18. What will be the output of the program?


#include<stdio.h>
int main()
{
int i=0;
for(; i<=5; i++);
printf("%d", i);
return 0;
}

A B
0, 1, 2, 3, 4, 5 5
. .
C D
1, 2, 3, 4 6
. .

19. What will be the output of the program?


#include<stdio.h>
int main()
{
int i=3;
switch(i)
{
case 1:
printf("Hello\n");
case 2:
printf("Hi\n");
case 3:
continue;
default:
printf("Bye\n");
}
return 0;
}

A B
Error: Misplaced continue Bye
. .
C D
No output Hello Hi
. .

20. What will be the output of the program?


#include<stdio.h>
int main()
{
int i=4;
switch(i)
{
default:
printf("This is default\n");
case 1:
printf("This is case 1\n");
break;
case 2:
printf("This is case 2\n");
break;
case 3:
printf("This is case 3\n");
}
return 0;
}

A This is default B This is case 3


. This is case 1 . This is default
C This is case 1 D
This is default
. This is case 3 .
21. The keyword used to transfer control from a function back to the calling
function is
A B
switch goto
. .
C D
go back return
. .

22. How many times the program will print "IndiaBIX" ?

#include<stdio.h>
int main()
{
printf("IndiaBIX");
main();
return 0;
}
A B
Infinite times 32767 times
. .
C D
65535 times Till stack overflows
. .

23. Input/output function prototypes and macros are defined in which header
file?
A B
conio.h stdlib.h
. .
C D
stdio.h dos.h
. .

24. What will be output if you compile and execute the above code?

int main()
{
char f=255.0;
printf("%d",sizeof(f++));
return 0;
}

(a)1
(b)8
(c)10
(d)Compiler error
25. What will be output if you compile and execute the above code?
#define int long
#define cal(x,y,z) x*y*z
int main(){
int a=2;
int b=cal(a++,a++,a++);
printf("%d,%d" ,a,b);
return 0;
}

(a)5,0
(b)5,125
(c)5,60
(d)Compiler error

You might also like