C-Language Programming MCQs > FREE SET - 2

1. What will be the output of the following program?
#include
int main()
{
int i=4, j=-1, k=0, w, x, y, z;
w = i || j || k;
x = i && j && k;
y = i || j &&k;
z = i && j || k;
printf("%d, %d, %d, %d", w, x, y, z);
return 0;
}
A 1, 1, 1, 1
B 1, 1, 0, 1
C 1, 0, 0, 1
D 1, 0, 1, 1

Free MCQs www.sharemcq.com     Answer: Option D
Explanation:
Available Soon.

2. What will be the output of the following program?
#include
int main()
{
int i=-3, j=2, k=0, m;
m = ++i && ++j || ++k;
printf("%d, %d, %d, %d", i, j, k, m);
return 0;
}
A 1, 2, 0, 1
B -3, 2, 0, 1
C -2, 3, 0, 1
D 2, 3, 1, 1

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

3. What will be the output of the following program?
#include
int main()
{
int x=4, y, z;
y = --x;
z = x--;
printf("%d, %d, %d", x, y, z);
return 0;
}
A 4, 3, 3
B 4, 3, 2
C 3, 3, 2
D 2, 3, 3

Free MCQs www.sharemcq.com     Answer: Option D
Explanation:
Available Soon.

4. What will be the output of the following program?
#include
int main()
{
int i=3;
i = i++;
printf("%d", i);
return 0;
}
A 3
B 4
C 5
D 6

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

5. What will be the output of the following program?
#include
int main()
{
int a=100, b=200, c;
c = (a == 100 || b > 200);
printf("c=%d", c);
return 0;
}
A c=100
B c=200
C c=1
D c=300

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

6. What will be the output of the following program?
#include
int main()
{
int x=55;
printf("%d, %d, %d", x<=55, x=40, x>=10);
return 0;
}
A 1, 40, 1
B 1, 55, 1
C 1, 55, 0
D 1, 1, 1

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

7. What will be the output of the following program?
#include
int main()
{
int i=2;
printf("%d, %d", ++i, ++i);
return 0;
}
A 3, 4
B 4, 3
C 4, 4
D Output may vary from compiler to compiler

Free MCQs www.sharemcq.com     Answer: Option D
Explanation:
Available Soon.

8. What will be the output of the following program?
#include
int main()
{
int k, num=30;
k = (num>5 ? (num <=10 ? 100 : 200): 500);
printf("%d", num);
return 0;
}
A 200
B 30
C 100
D 500

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

9. What will be the output of the following program?
#include
int main()
{
int i=2;
int j = i + (1, 2, 3, 4, 5);
printf("%d", j);
return 0;
}
A 4
B 7
C 6
D 5

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

10. Which of the following is the correct order if calling functions in the below code?
a = f1(23, 14) * f2(12/4) + f3();
A f1, f2, f3
B f3, f2, f1
C Order may vary from compiler to compiler
D None of above

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

11. What will be the output of the following program?
#include
int main()
{
char ch;
ch = 'A';
printf("The letter is");
printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);
printf("Now the letter is");
printf("%c", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');
return 0;
}
A The letter is a Now the letter is A
B The letter is A Now the letter is a
C Error
D None of above

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

12. What will be the output of the following program?
#include
#define MAN(x, y) ((x)>(y)) ? (x):(y);
int main()
{
int i=10, j=5, k=0;
k = MAN(++i, j++);
printf("%d, %d, %d", i, j, k);
return 0;
}
A 12, 6, 12
B 11, 5, 11
C 11, 5, Garbage
D 12, 6, Garbage

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

13. What will be the output of the following program?
#include
#define SQR(x)(x*x)
int main()
{
int a, b=3;
a = SQR(b+2);
printf("%d", a);
return 0;
}
A 25
B 11
C Error
D Garbage value

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

14. What will be the output of the following program?
#include
#define CUBE(x) (x*x*x)
int main()
{
int a, b=3;
a = CUBE(b++);
printf("%d, %d", a, b);
return 0;
}
A 9, 4
B 27, 4
C 27, 6
D Error

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

15. What will be the output of the following program?
#include
#define PRINT(int) printf("int=%d, ", int);
int main()
{
int x=2, y=3, z=4;
PRINT(x);
PRINT(y);
PRINT(z);
return 0;
}
A int=2, int=3, int=4
B int=2, int=2, int=2
C int=3, int=3, int=3
D int=4, int=4, int=4

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

16. What will be the output of the following program?
#include
#define SWAP(a, b) int t; t=a, a=b, b=t;
int main()
{
int a=10, b=12;
SWAP(a, b);
printf("a = %d, b = %d", a, b);
return 0;
}
A a = 10, b = 12
B a = 12, b = 10
C Error: Declaration not allowed in macro
D Error: Undefined symbol 't'

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

17. What will be the output of the following program?
#include
#define FUN(i, j) i##j
int main()
{
int va1=10;
int va12=20;
printf("%d", FUN(va1, 2));
return 0;
}
A 10
B 20
C 1020
D 12

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

18. What will be the output of the following program?
#include
#define MAX(a, b) (a > b ? a : b)
int main()
{
int x;
x = MAX(3+2, 2+7);
printf("%d", x);
return 0;
}
A 8
B 9
C 6
D 5

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

19. What will be the output of the following program?
#include
#define MIN(x, y) (xint main()
{
int x=3, y=4, z;
z = MIN(x+y/2, y-1);
if(z > 0)
printf("%d", z);
return 0;
}
A 3
B 4
C 0
D No output

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

20. What will be the output of the following program?
#include
#define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c)
int main()
{
int x;
x = MAX(3+2, 2+7, 3+7);
printf("%d", x);
return 0;
}
A 5
B 9
C 10
D 3+7

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

21. Point out the error in the program
#include
int main()
{
int i;
#if A
printf("Enter any number:");
scanf("%d", &i);
#elif B
printf("The number is odd");
return 0;
}
A Error: unexpected end of file because there is no matching #endif
B The number is odd
C Garbage values
D None of above

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

22. What will be the output of the following program?
#include
#include
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s", strcpy(str2, strcat(str1, str2)));
return 0;
}
A Hello
B World
C Hello World
D WorldHello

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

23. What will be the output of the following program?
#include
int main()
{
char p[] = "%d";
p[1] = 'c';
printf(p, 65);
return 0;
}
A A
B a
C c
D 65

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

24. What will be the output of the following program?
#include
#include
int main()
{
printf("%d", strlen("123456"));
return 0;
}
A 6
B 12
C 7
D 2

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

25. What will be the output of the following program?
#include
int main()
{
printf(5+"Good Morning");
return 0;
}
A Good Morning
B Good
C M
D Morning

Free MCQs www.sharemcq.com     Answer: Option D
Explanation:
Available Soon.

26. What will be the output of the following program?
#include
#include
int main()
{
static char str1[] = "dills";
static char str2[20];
static char str3[] = "Daffo";
int i;
i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
printf("%d", i);
return 0;
}
A 0
B 1
C 2
D 4

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

27. What will be the output of the following program?
#include
#include
int main()
{
static char s[] = "Hello!";
printf("%d", *(s+strlen(s)));
return 0;
}
A 8
B 0
C 16
D Error

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

28. What will be the output of the following program?
#include
int main()
{
int i;
char a[] = "\\0";
if(printf("%s", a))
printf("The string is empty");
else
printf("The string is not empty");
return 0;
}
A The string is empty
B The string is not empty
C No output
D 0

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

29. If char=1, int=4, and float=4 bytes size, What will be the output of the program?
#include
int main()
{
char ch = 'A';
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
return 0;
}
A 1, 2, 4
B 1, 4, 4
C 2, 2, 4
D 2, 4, 8

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

30. What will be the output of the following program?
#include
int main()
{
char str1[] = "Hello";
char str2[10];
char *t, *s;
s = str1;
t = str2;
while(*t=*s)
*t++ = *s++;
printf("%s", str2);
return 0;
}
A Hello
B HelloHello
C No output
D ello

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

31. What will be the output of the following program?
#include
int main()
{
char str[] = "Nagpur";
str[0]='K';
printf("%s, ", str);
str = "Kanpur";
printf("%s", str+1);
return 0;
}
A Kagpur, Kanpur
B Nagpur, Kanpur
C Kagpur, anpur
D Error

Free MCQs www.sharemcq.com     Answer: Option D
Explanation:
Available Soon.

32. What will be the output of the following program?
#include
#include
int main()
{
char sentence[80];
int i;
printf("Enter a line of text");
gets(sentence);
for(i=strlen(sentence)-1; i >=0; i--)
putchar(sentence[i]);
return 0;
}
A The sentence will get printed in same order as it entered
B The sentence will get printed in reverse order
C Half of the sentence will get printed
D None of above

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

33. If the size of pointer is 4 bytes then what will be the output of the program?
#include
int main()
{
char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
printf("%d, %d", sizeof(str), strlen(str[0]));
return 0;
}
A 22, 4
B 25, 5
C 24, 5
D 20, 2

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

34. What will be the output of the following program?
#include
int main()
{
int i;
char a[] = "\\0";
if(printf("%s", a))
printf("The string is not empty");
else
printf("The string is empty");
return 0;
}
A The string is not empty
B The string is empty
C No output
D 0

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

35. What will be the output of the following program?
#include
#include
int main()
{
char str1[5], str2[5];
int i;
gets(str1);
gets(str2);
i = strcmp(str1, str2);
printf("%d", i);
return 0;
}
A Unpredictable integer value
B 0
C -1
D Error

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

36. What will be the output of the following program?
#include
int main()
{
char str1[] = "Hello";
char str2[] = "Hello";
if(str1 == str2)
printf("Equal");
else
printf("Unequal");
return 0;
}
A Equal
B Unequal
C Error
D None of above

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

37. What will be the output of the following program?
#include
#include
int main()
{
printf("%c", "abcdefgh"[4]);
return 0;
}
A Error
B d
C e
D abcdefgh

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

38. Which of the following statement is correct?
A strcmp(s1, s2) returns a number less than 0 if s1>s2
B strcmp(s1, s2) returns a number greater than 0 if s1
C strcmp(s1, s2) returns 0 if s1==s2
D strcmp(s1, s2) returns 1 if s1==s2

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

39. What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample Good Morning
/* sample.c */
#include
int main(int argc, char *argv[])
{
printf("%d %s", argc, argv[1]);
return 0;
}
A 3 Good
B 2 Good
C Good Morning
D 3 Morning

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

40. What will be the output of the following program?
#include
int main()
{
int y=128;
const int x=y;
printf("%d", x);
return 0;
}
A 128
B Garbage value
C Error
D 0

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

41. What will be the output of the following program?
#include
int main()
{
const int x=5;
const int *ptrx;
ptrx = &x;
*ptrx = 10;
printf("%d", x);
return 0;
}
A 5
B 10
C Error
D Garbage value

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

42. What will be the output of the following program?
#include
int main()
{
const char *s = "";
char str[] = "Hello";
s = str;
while(*s)
printf("%c", *s++);
return 0;
}
A Error
B H
C Hello
D Hel

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

43. What will be the output of the following program?
#include
int main()
{
const int i=0;
printf("%d", i++);
return 0;
}
A 10
B 11
C No output
D Error: ++needs a value

Free MCQs www.sharemcq.com     Answer: Option D
Explanation:
Available Soon.

44. What will be the output of the following program?
#include
int main()
{
const c = -11;
const int d = 34;
printf("%d, %d", c, d);
return 0;
}
A Error
B -11, 34
C 11, 34
D None of these

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

45. What do the following declaration signify?
int *ptr[30];
A ptr is a pointer to an array of 30 integer pointers.
B ptr is a array of 30 pointers to integers.
C ptr is a array of 30 integer pointers.
D ptr is a array 30 pointers.

Free MCQs www.sharemcq.com     Answer: Option B
Explanation:
Available Soon.

46. Declare the following statement?
A pointer to an array of three chars.
A char *ptr[3]();
B char (*ptr)*[3];
C char (*ptr[3])();
D char (*ptr)[3];

Free MCQs www.sharemcq.com     Answer: Option D
Explanation:
Available Soon.

47. What do the following declaration signify?
char *arr[10];
A arr is a array of 10 character pointers.
B arr is a array of function pointer.
C arr is a array of characters.
D arr is a pointer to array of characters.

Free MCQs www.sharemcq.com     Answer: Option A
Explanation:
Available Soon.

48. What do the following declaration signify?
int (*pf)();
A pf is a pointer to function.
B pf is a function pointer.
C pf is a pointer to a function which return int
D pf is a function of pointer variable.

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

49. Declare the following statement?
"A pointer to a function which receives an int pointer and returns float pointer."
A float *(ptr)*int;
B float *(*ptr)(int)
C float *(*ptr)(int*)
D float (*ptr)(int)

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.

50. What do the following declaration signify?
void *cmp();
A cmp is a pointer to an void type.
B cmp is a void type pointer variable.
C cmp is a function that return a void pointer.
D cmp function returns nothing.

Free MCQs www.sharemcq.com     Answer: Option C
Explanation:
Available Soon.


No comments:

Post a Comment

Your Feedback is hearty Requested to make the MCQs Collection better.

Popular Posts