C-Language Programming MCQs > FREE SET - 3

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

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

2. What will be the output of the following program?
#include
int main()
{
char str[]="C-program";
int a = 5;
printf(a >10?"Ps":"%s", str);
return 0;
}
A C-program
B Ps
C Error
D None of above

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

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

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

4. What will be the output of the following program?
#include
int main()
{
unsigned int i = 65535; /* Assume 2 byte integer*/
while(i++ != 0)
printf("%d",++i);
printf("");
return 0;
}
A Infinite loop
B 0 1 2 ... 65535
C 0 1 2 ... 32767 - 32766 -32765 -1 0
D No output

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

5. What will be the output of the following program?
#include
int main()
{
int x = 3;
float y = 3.0;
if(x == y)
printf("x and y are equal");
else
printf("x and y are not equal");
return 0;
}
A x and y are equal
B x and y are not equal
C Unpredictable
D No output

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

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

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

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

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

8. What will be the output of the following program?
#include
int main()
{
int x = 10, y = 20;
if(!(!x) && x)
printf("x = %d", x);
else
printf("y = %d", y);
return 0;
}
A y =20
B x = 0
C x = 10
D x = 1

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

9. What will be the output of the following program?
#include
int main()
{
char j=1;
while(j < 5)
{
printf("%d, ", j);
j = j+1;
}
printf("");
return 0;
}
A 1 2 3 ... 127
B 1 2 3 ... 255
C 1 2 3 ... 127 128 0 1 2 3 ... infinite times
D 1, 2, 3, 4

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

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

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

11. What will be the output of the following program?
#include
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A 2, 1, 15
B 1, 2, 5
C 3, 2, 15
D 2, 3, 20

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

12. What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?
#include
int main()
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
printf("%u, %u", a+1, &a+1);
return 0;
}
A 65474, 65476
B 65480, 65496
C 65480, 65488
D 65474, 65488

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

13. What will be the output of the program in Turb C (under DOS)?
#include
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
A 1, 2, 3, 4, 5,
B Garbage value, 1, 2, 3, 4,
C 0, 1, 2, 3, 4,
D 2, 3, 4, 5, 6,

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

14. What will be the output of the following program?
#include
int main()
{
int arr[1]={10};
printf("%d", 0[arr]);
return 0;
}
A 1
B 10
C 0
D 6

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

15. What will be the output of the program if the array begins at address 65486?
#include
int main()
{
int arr[] = {12, 14, 15, 23, 45};
printf("%u, %u", arr, &arr);
return 0;
}
A 65486, 65488
B 65486, 65486
C 65486, 65490
D 65486, 65487

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

16. What will be the output of the program if the array begins 1200 in memory?
#include
int main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u", arr, &arr[0], &arr);
return 0;
}
A 1200, 1202, 1204
B 1200, 1200, 1200
C 1200, 1204, 1208
D 1200, 1202, 1200

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

17. Which of the following statements are correct about the program below?
#include
int main()
{
int size, i;
scanf("%d", &size);
int arr[size];
for(i=1; i<=size; i++)
{
scanf("%d", arr[i]);
printf("%d", arr[i]);
}
return 0;
}
A The code is erroneous since the subscript for array used in for loop is in the range 1 to size.
B The code is erroneous since the values of array are getting scanned through the loop.
C The code is erroneous since the statement declaring array is invalid.
D The code is correct and runs successfully.

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

18. In a file contains the line "I am a boy\\r\\n" then on reading this line into the array str using fgets(). What will str contain?
A "I am a boy\\r\\n\\0"
B "I am a boy\\r\\0"
C "I am a boy\\n\\0"
D "I am a boy"

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

19. What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp;
fp = fopen("source.txt", "rb");
A open "source.txt" in binary mode for reading
B open "source.txt" in binary mode for reading and writing
C Create a new file "source.txt" for reading and writing
D None of above

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

20. What does fp point to in the program?
#include
int main()
{
FILE *fp;
fp=fopen("trial", "r");
return 0;
}
A The first character in the file
B A structure which contains a char pointer which points to the first character of a file.
C The name of the file.
D The last character in the file.

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

21. Which of the following operations can be performed on the file "NOTES.TXT" using the below code?
FILE *fp;
fp = fopen("NOTES.TXT", "r+");
A Reading
B Writing
C Appending
D Read and Write

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

22. To print out a and b given below, which of the following printf() statement will you use?
#include
float a=3.14;
double b=3.14;
A printf("%f %lf", a, b);
B printf("%Lf %f", a, b);
C printf("%Lf %Lf", a, b);
D printf("%f %Lf", a, b);

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

23. Which files will get closed through the fclose() in the following program?
#include
int main()
{
FILE *fs, *ft, *fp;
fp = fopen("A.C", "r");
fs = fopen("B.C", "r");
ft = fopen("C.C", "r");
fclose(fp, fs, ft);
return 0;
}
A "A.C" "B.C" "C.C"
B "B.C" "C.C"
C "A.C"
D Error in fclose()

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

24. Consider the following program and what will be content of t?
#include
int main()
{
FILE *fp;
int t;
fp = fopen("DUMMY.C", "w");
t = fileno(fp);
printf("%d", t);
return 0;
}
A size of "DUMMY.C" file
B The handle associated with "DUMMY.C" file
C Garbage value
D Error in fileno()

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

25. What will be the output of the following program?
#include
int main()
{
int k=1;
printf("%d == 1 is" "%s", k, k==1?"TRUE":"FALSE");
return 0;
}
A k == 1 is TRUE
B 1 == 1 is TRUE
C 1 == 1 is FALSE
D K == 1 is FALSE

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

26. What will be the output of the following program?
#include
int main()
{
float a=3.15529;
printf("%2.1f", a);
return 0;
}
A 3.00
B 3.15
C 3.2
D 3

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

27. What will be the output of the following program?
#include
int main()
{
printf("%c", ~('C'*-1));
return 0;
}
A A
B B
C C
D D

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

28. What will be the output of the following program?
#include
int main()
{
char *p;
p="%d";
p++;
p++;
printf(p-2, 23);
return 0;
}
A 21
B 23
C Error
D No output

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

29. What will be the output of the following program?
#include
int main()
{
FILE *ptr;
char i;
ptr = fopen("myfile.c", "r");
while((i=fgetc(ptr))!=NULL)
printf("%c", i);
return 0;
}
A Print the contents of file "myfile.c"
B Print the contents of file "myfile.c" upto NULL character
C Infinite loop
D Error in program

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

30. What will be the output of the following program?
#include
int main()
{
printf("%%%%");
return 0;
}
A %%%%%
B %%
C No output
D Error

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

31. What will be the output of the following program?
#include
int main()
{
int a=250;
printf("%1d", a);
return 0;
}
A 1250
B 2
C 50
D 250

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

32. What will be the output of the following program?
#include
int main()
{
FILE *fp;
char ch, str[7];
fp=fopen("try.c", "r"); /* file 'try.c' contains "This is Nagpur" */
fseek(fp, 9L, SEEK_CUR);
fgets(str, 5, fp);
puts(str);
return 0;
}
A agpur
B gpur
C Nagp
D agpu

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

33. What will be the output of the program if value 25 given to scanf()?
#include
int main()
{
int i;
printf("%d", scanf("%d", &i));
return 0;
}
A 25
B 2
C 1
D 5

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

34. Point out the error in the program given below?
#include
int main()
{
char ch;
int i;
scanf("%c", &i);
scanf("%d", &ch);
printf("%c %d", ch, i);
return 0;
}
A Error: suspicious char to in conversion in scanf()
B Error: we may not get input for second scanf() statement
C No error
D None of above

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

35. Point out the error in the program given below?
#include
int main()
{
FILE *fp;
fp=fopen("trial", "r");
fseek(fp, "20", SEEK_SET);
fclose(fp);
return 0;
}
A Error: unrecognised Keyword SEEK_SET
B Error: fseek() long offset value
C No error
D None of above

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

36. Point out the error in the program given below?
#include
/* Assume there is a file called 'file.c' in c:\\tc directory. */
int main()
{
FILE *fp;
fp=fopen("c:\\tc\\file.c", "r");
if(!fp)
printf("Unable to open file.");
fclose(fp);
return 0;
}
A No error, No output.
B Program crashes at run time.
C Output: Unable to open file.
D None of above

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

37. Point out the error/warning in the program?
#include
int main()
{
unsigned char ch;
FILE *fp;
fp=fopen("trial", "r");
while((ch = getc(fp))!=EOF)
printf("%c", ch);
fclose(fp);
return 0;
}
A Error: in unsigned char declaration
B Error: while statement
C No error
D It prints all characters in file "trial"

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

38. Which of the following statement is correct about the program?
#include
int main()
{
FILE *fp;
char ch;
int i=1;
fp = fopen("myfile.c", "r");
while((ch=getc(fp))!=EOF)
{
if(ch == '\\n')
i++;
}
fclose(fp);
return 0;
}
A The code counts number of characters in the file
B The code counts number of words in the file
C The code counts number of blank lines in the file
D The code counts number of lines in the file

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

39. In the following code, the P2 is Integer Pointer or Integer?
typedef int *ptr;
ptr p1, p2;
A Integer
B Integer pointer
C Error in declaration
D None of above

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

40. In the following code what is 'P'?
typedef char *charp;
const charp P;
A P is a constant
B P is a character constant
C P is character type
D None of above

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

41. What is x in the following program?
#include
int main()
{
typedef char (*(*arrfptr[3])())[10];
arrfptr x;
return 0;
}
A x is a pointer
B x is an array of three pointer
C x is an array of three function pointers
D Error in x declaration

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

42. What will be the output of the following program?
#include
int main()
{
enum color{red, green, blue};
typedef enum color mycolor;
mycolor m = red;
printf("%d", m);
return 0;
}
A 1
B 0
C 2
D red

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

43. What will be the output of the following program?
#include
int main()
{
typedef int arr[5];
arr iarr = {1, 2, 3, 4, 5};
int i;
for(i=0; i<4; i++)
printf("%d,", iarr[i]);
return 0;
}
A 1, 2, 3, 4
B 1, 2, 3, 4, 5
C No output
D Error: Cannot use typedef with an array

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

44. What will be the output of the following program?
#include
int main()
{
typedef int LONG;
LONG a=4;
LONG b=68;
float c=0;
c=b;
b+=a;
printf("%d,", b);
printf("%f", c);
return 0;
}
A 72, 68.000000
B 72.000000, 68
C 68.000000, 72.000000
D 68, 72.000000

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

45. What will be the output of the following program?
#include
int main()
{
typedef float f;
static f *fptr;
float fval = 90;
fptr = &fval;
printf("%f", *fptr);
return 0;
}
A 9
B 0
C 90.000000
D 90

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

46. What will be the output of the following program?
#include
typedef struct error {int warning, err, exception;} ERROR;
int main()
{
ERROR e;
e.err=1;
printf("%d", e.err);
return 0;
}
A 0
B 1
C 2
D Error

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

47. Point out the error in the following code?
typedef struct
{
int data;
NODEPTR link;
}*NODEPTR;
A Error: in *NODEPTR
B Error: typedef cannot be used until it is defined
C No error
D None of above

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

48. 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 -2, 3, 1, 1
B 2, 3, 1, 2
C 1, 2, 3, 1
D 3, 3, 1, 2

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

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

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

50. What will be the output of the following program?
#include
int main()
{
static int a[20];
int i = 0;
a[i] = i ;
printf("%d, %d, %d", a[0], a[1], i);
return 0;
}
A 1, 0, 1
B 1, 1, 1
C 0, 0, 0
D 0, 1, 0

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