You are on page 1of 11

DATATYPES AND FORMAT SPECIFIERS

1. Which of the following is integral data type?

A. void B) char C) float D) double

Answer: char

2. How would you round off a value from 1.66 to 2.0?


A. Ceil(1.66) B. floor(1.66) C. roundup(1.66) D. roundto (1.66)

Answer: ceil(1.66)

3. A c source file can be


A. compiled only B. interpreted only
C. Both compiled and interpreted D.nothing
Answer: both compiled and interpreted
4. What is the correct prototype of printf function?

A.printf (char *p,...); B.printf (const *char *p,...);

C.printf (const char *p,...); D.printf (const *char p,...);

Answer: printf(const char *p…)

5. What is the proto-type of scanf function?

Answer: int scanf(const char *format, ...);

6. main ()
{
Int i=0xffffffff;
Printf(“%d\n”,i);
}
Answer: -1
7. main()

printf (“%%%s”,”hello”);

}
A. %s B. Hello C. %%s D. %hello
Answer: %hello

8. main ()
{

int x=48;

printf(“x=%s\n”,x);

A. 10 B. 0 C. Run time error D. Compilation error


Answer: Runtime error
9. main ()
{

int i= 24;

printf(“%xd”,i);

}
A. 18 B. 24 C. 18d D. Compile time error
Answer: 18d
10. main ()
{

int i=10;

Printf(“%d”,j);

Printf(“%d”,i);

}int j=20;

A. J=20,i=10. B. J=junk, i=10. C. Compile time error D. Run time error


Answer: Compile time error
11. main ( )
{

int i,j;

i=06;

j=09;
printf (“%d\n%d”,i,j);

A. 6 9 B. 6 11 C. 06 09 D. Compilation error
Answer: compilation error
12. main ()
{

int i=1,2;

printf(“%d”,i);

}
A. 1 B.2 C. Compilation Error D. None
Answer: compilation error

13. int a=5;

main ()

printf (“%d”, i);

}int a;

A. 5 B. 6 C. Error D. None
Answer: error
14. main ()

printf(“%c %s ”,’he’,”hello”);

A. e hello B. hehello C. compile time error D. h hello


Answer: e hello
15. int main()
{
char num = '\010';
printf("%d", num);
}
ans :8
16. int main()

int i=43;

printf("%d\n",printf("%d",printf("%d",i)));

A. 4321 B.43434 C.4311 D. error

Answer: 4321

17. main()

Printf(“%c”,’1’+1);

A. 2 B. 49 C. 50 D. Error
Answer: 2
18. main ()

int a=5;

Printf (“%d”+1, a);

A. 5 B. compile time error C. 6 D. d


Answer: d
19. main ()

#include<stdio.h>

int a =90;

printf(“%d”,a);

A. 90 B. Compilation error C. Linker error D. Run time error


Answer: 90
20. main ()

Printf(“%[s]%s”,”hello”);

A. hellohello B. %[s]hello C. %[s]%s D. Run time error


Answer: [s]hello

21. int main()


{
void num=10;
printf("%v", num);
}
ans: compilation error.(Void is not a valid data type for declaring
variables.)
22. What is the output of the given question when input of s is 5?
main ()
{
int s;
s=scanf(“%d”,&s);
printf(“%d”,s);

Answer: runtime error

23. int main()


{
char num=127;
num=num+1;
Printf(“%d”,num);
}
Ans: -128
24. main()
{

float k=3.4156;

printf("%f %f ",floor(k),ceil(k));
}

ans: 3.000000 4.000000

25. main()

int number =25;

char name ='A';

printf("The addition of the name and the number is %o ",name+number);

ans: The addition of the name and the number is 132

26. main()

printf("%u",main);

ans: 0

27. main()

printf("%p",main);

ans: starting address of main function x:y (segment : offset). Each time u
run starting address will change. Function name always gives starting
address of that function.

28. main()

printf("%u",main());

}
ans: infinite loop or till stack overflows. main function is called recursively
infinite times or till stack overflows

29. main()

printf("%d", sizeof(""));

ans: 1 (sizeof included null character. It is a null string)

30. main()

printf("%f %f",floor(-2.8),ceil(-2.8));

ans: -3.000000 -2.000000

31. main()

printf("\%d ", 100);

printf("\\% ");

printf("%% ");

printf("\%%");

ans: 100 \% % %

32. main()

char c;

int i = 456;
c = i;

printf("%d", c);

ans: -56

33. main()

int d,a=5,b=3,c=(a,b);

d=(a,b);

printf("%d %d",c,d);

ans: 3 3 (from 321 to 324 think about comma operator)

37. main()

int a=5,b=3,c=a,d;

d=(a,b);

printf("%d %d",c,d);

ans: 5 3

38. main()

int a=5,b=3,c=(a,b),d;

d=(a,b);

printf("%d %d",c,d);

ans: 3 3
39. main()

int a=5,b=3,c=(a,b),d;

d=a,b;

printf("%d %d",c,d);

ans: 3 5 (from 321 to 324 think about comma operator)

40. main()

int z = 4;

printf("%d", printf(" %d %d ", z, z));

ans: 4 4 5 (three spaces are there total five characters will be printed by
printf statement)

41. int a=1;

int ab=4;

int main()

int b=3,a=2;

printf("%i*/%i*/%*/i",a,b,ab);

ans: 2*/3*/%*/i

42. main()

int x;

printf("\n%d",x=0,x=20,x=40);
}ans: 0

43. main()

printf("%u",-1);

ans: 65535

44. int main()

printf("%d", 5.00);

return 0;

Ans: 0(when we print the integer with .000 and many zero's as an
extension then output will be 0.)

45. main()

int a=5,b=6,c=7;

printf(“%d %d %d”);

printf(“%d%d%d”,a,b,c);

a. Garbage value, garbage value, garbage value.


567
b. 5 6 7
567
c. 7 6 5
567
d. Compiler error

Answer: Garbage value, garbage value, garbage value.


567

You might also like