Explore topic-wise MCQs in C Programming.

This section includes 391 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.

351.

What will be the output for the given code printf('\n The number is %07d',1212);

A. The number is 0001212
B. The number is 1212
C. The number is 1212
D. The number is 1212000
Answer» B. The number is 1212
352.

What will be the output of the 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
Answer» E.
353.

What will be the output of the 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
Answer» D. Error in program
354.

What will be the output of the program if value 25 given to scanf()? #include int main() { int i; printf("%d\n", scanf("%d", &i)); return 0; }

A. 25
B. 2
C. 1
D. 5
Answer» D. 5
355.

What will be the output of the program ? #include int main() { printf("%%%%\n"); return 0; }

A. %%%%%
B. %%
C. No output
D. Error
Answer» C. No output
356.

What will be the output of the program ? #include int main() { FILE *fp; unsigned char ch; /* file 'abc.c' contains "This is IndiaBIX " */ fp=fopen("abc.c", "r"); if(fp == NULL) { printf("Unable to open file"); exit(1); } while((ch=getc(fp)) != EOF) printf("%c", ch); fclose(fp); printf("\n", ch); return 0; }

A. This is IndiaBIX
B. This is
C. Infinite loop
D. Error
Answer» D. Error
357.

What will be the output of the program ? #include int main() { char *p; p="%d\n"; p++; p++; printf(p-2, 23); return 0; }

A. 21
B. 23
C. Error
D. No output
Answer» C. Error
358.

We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind()

A. 1
B.
Answer» B.
359.

Point out the error in the program? #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
Answer» C. No error
360.

In a call to printf() function the format specifier %b can be used to print binary equivalent of an integer.

A. 1
B.
Answer» C.
361.

If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program? #include int main() { FILE *fs, *ft; char c[10]; fs = fopen("source.txt", "r"); c[0] = getc(fs); fseek(fs, 0, SEEK_END); fseek(fs, -3L, SEEK_CUR); fgets(c, 5, fs); puts(c); return 0; }

A. friend
B. frien
C. end
D. Error in fseek();
Answer» D. Error in fseek();
362.

Point out the error in the program? #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
Answer» D. None of above
363.

Point out the error in the program? #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
Answer» C. No error
364.

A file written in text mode can be read back in binary mode.

A. Yes
B. No
Answer» C.
365.

What will be the output of the program ? #include int main() { int a=250; printf("%1d \n", a); return 0; }

A. 1250
B. 2
C. 50
D. 250
Answer» E.
366.

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\n", t); return 0; }

A. size of "DUMMY.C" file
B. The handle associated with "DUMMY.C" file
C. Garbage value
D. Error in fileno()
Answer» C. Garbage value
367.

Which of the following statement is correct about the program? #include int main() { FILE *fp; char str[11], ch; int i=0; fp = fopen("INPUT.TXT", "r"); while((ch=getc(fp))!=EOF) { if(ch == '\n' || ch == ' ') { str[i]='\0'; strrev(str); printf("%s", str); i=0; } else str[i++]=ch; } fclose(fp); return 0; }

A. The code writes a text to a file
B. The code reads a text files and display its content in reverse order
C. The code writes a text to a file in reverse order
D. None of above
Answer» C. The code writes a text to a file in reverse order
368.

Out of fgets() and gets() which function is safe to use?

A. gets()
B. fgets()
Answer» C.
369.

To scan a and b given below, which of the following scanf() statement will you use? #include float a; double b;

A. scanf("%f %f", &a, &b);
B. scanf("%Lf %Lf", &a, &b);
C. scanf("%f %Lf", &a, &b);
D. scanf("%f %lf", &a, &b);
Answer» E.
370.

What will be the output of the program ? #include int main() { printf("%c\n", ~('C'*-1)); return 0; }

A. A
B. B
C. C
D. D
Answer» C. C
371.

Offset used in fseek() function call can be a negative number.

A. 1
B.
Answer» B.
372.

On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"? #include int main() { int i, fss; char ch, source[20] = "source.txt", target[20]="target.txt", t; FILE *fs, *ft; fs = fopen(source, "r"); ft = fopen(target, "w"); while(1) { ch=getc(fs); if(ch==EOF) break; else { fseek(fs, 4L, SEEK_CUR); fputc(ch, ft); } } return 0; }

A. r n
B. Trh
C. err
D. None of above
Answer» C. err
373.

Can we specify a variable filed width in a scanf() format string?

A. Yes
B. No
Answer» C.
374.

What will be the output of the program ? #include int main() { int k=1; printf("%d == 1 is" "%s\n", 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
Answer» C. 1 == 1 is FALSE
375.

What will be the output of the program ? #include char *str = "char *str = %c%s%c; main(){ printf(str, 34, str, 34);}"; int main() { printf(str, 34, str, 34); return 0; }

A. char *str = "char *str = %c%s%c; main(){ printf(str, 34, str, 34);}"; main(){ printf(str, 34, str, 34);}
B. char *str = %c%s%c; main(){ printf(str, 34, str, 34);}
C. No output
D. Error in program
Answer» B. char *str = %c%s%c; main(){ printf(str, 34, str, 34);}
376.

What will be the output of the program ? #include int main() { float a=3.15529; printf("%2.1f\n", a); return 0; }

A. 3
B. 3.15
C. 3.2
D. 3
Answer» D. 3
377.

A text stream is an ordered sequence of characters composed into lines, each line consisting of zero or more characters plus a terminating new-line character.

A. 1
B.
Answer» B.
378.

Point out the correct statements about the program? #include int main() { FILE *fptr; char str[80]; fptr = fopen("f1.dat", "w"); if(fptr == NULL) printf("Cannot open file"); else { while(strlen(gets(str))>0) { fputs(str, fptr); fputs("\n", fptr); } fclose(fptr); } return 0; }

A. The code copies the content of one file to another
B. The code writes strings that are read from the keyboard into a file.
C. The code reads a file
D. None of above
Answer» C. The code reads a file
379.

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"
Answer» B. Error: while statement
380.

Will the following program work? #include int main() { int n=5; printf("n=%*d\n", n, n); return 0; }

A. Yes
B. No
Answer» B. No
381.

stderr, stdin, stdout are FILE pointers

A. Yes
B. No
C. Yes
D. No
Answer» B. No
382.

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
Answer» E.
383.

Point out the error in the program? #include #include int main() { unsigned char; FILE *fp; fp=fopen("trial", "r"); if(!fp) { printf("Unable to open file"); exit(1); } fclose(fp); return 0; }

A. Error: in unsigned char statement
B. Error: unknown file pointer
C. No error
D. None of above
Answer» D. None of above
384.

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
Answer» B. open "source.txt" in binary mode for reading and writing
385.

While calling the fprintf() function in the format string conversion specifier %s can be used to write a character string in capital letters.

A. 1
B.
C. 1
D.
Answer» C. 1
386.

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.
Answer» C. The name of the file.
387.

What will be the content of 'file.c' after executing the following program? #include int main() { FILE *fp1, *fp2; fp1=fopen("file.c", "w"); fp2=fopen("file.c", "w"); fputc('A', fp1); fputc('B', fp2); fclose(fp1); fclose(fp2); return 0; }

A. B
B. AB
C. BB
D. Error in opening file 'file1.c'
Answer» B. AB
388.

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
Answer» E.
389.

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()
Answer» E.
390.

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);
Answer» B. printf("%Lf %f", a, b);
391.

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"
Answer» D. "I am a boy"