ExamTray App is now Available on Google Play EXAMTRAY android app link

 

C MCQ Questions and Answers on Console IO and Formatted IO

Image
C MCQ Questions and Answers

Study C MCQ Questions and Answers on Console Input and Output & Formatted Input and Output. Easily attend technical job interviews with these Multiple Choice Questions.

Go through C Theory Notes on Console IO and Formatted IO before attempting this test.



1) What is an Escape Sequence in C language.?
A) An escape sequence is a combination of two characters starting with Back Slash always.
B) An escape sequence is usually part of a string to tell compiler to produce New Lines, New tabs, Single or Double quotes etc
C) An escape sequence is used to format the output to look in desired way.
D) All the above
Answer [=]
D
Explanation:

eg. \n outputs new line. \t outputs tab i.e 4 or 8 white spaces.

2) Choose a C Formatted Input Output function below.
A) printf(), scanf()
B) sprintf(), sscanf()
C) fprintf(), fscanf()
D) All the above
Answer [=]
D
3) Choose a C unformatted input output function below.
A) gets(), puts()
B) getchar(), putchar()
C) A & B
D) None of the above
Answer [=]
C
4) What is the output of C program.? int main() { int a=123; printf("*%06d*",a); return 0; }
A) *123*
B) *6123*
C) *000123*
D) *006123*
Answer [=]
C
Explanation:

%6d reservers 6 columns. %Zero6d causes Remaining columns will be filled with Zero.

5) What is the output of C program.? int main() { int a=123456; printf("*%03d*",a); return 0; }
A) *123*
B) *6123*
C) *123456*
D) *012345*
Answer [=]
C
Explanation:

%3d reserves three columns. But 123456 is more than 3 columns. So width 3 will be ignored.

6) What is the output of C program.? int main() { int a=6543; printf("*%5d,*%-5d*",a,a); return 0; }
A) *56543,*56543*
B) * 6543,*6543 *
C) *6543 ,* 6543*
D) *6543,*6543*
Answer [=]
B
Explanation:

%5d reserves 5 columns. 6543 is aligned right. So One Space is filled in the first column. %-5d aligns 6543 left. So right side one Space is filled as 6543 is only a 4 digit number.

7) What is the output of C program.? int main() { float a=654.123456f; printf("%3.3f,%3.2f",a,a); return 0; }
A) 654,654
B) 654.123456,654.123456
C) 654.123,654.12
D) 654.000,654.00
Answer [=]
C
Explanation:

%3.3 reserves 3 columns. But the 654.123456 is a 9 column number. So only .3 will be treated as important to print 3 digit precision number. .2 prints number with 2 digit precision.

8) What is the output of C program.? int main() { char str[]="123"; printf("*%4s*%-4s*",str,str); return 0; }
A) *4123*4123*
B) * 123*123 *
C) *123 * 123*
D) *123*123*
Answer [=]
B
Explanation:

%4s reserves 4 columns. If the string length is less you can see spaces on the left side. %-4s also reserves 4 columns but aligns content on the right side.

9) Choose a correct statement about sprintf and sscanf functions.? char str[20];
A) sprintf(str,"formatstring",variables) prints output to console. sscanf(str,"formatstring",&variables) scans keyboard input and copies to str.
B) sprintf(str,"formatstring",variables) prints output to string str. sscanf(str,"formatstring",&variables) scans keyboard input and prints to console
C) sprintf(str,"formatstring",variables) prints output to string str. sscanf(str,"formatstring",&variables) scans input from str itself and assigns data to &variables.
D) None of the above
Answer [=]
C
Explanation:

Both functions SSCANF or SPRINTF avoid getting input from keyboard or displaying on Console / Screen.

10) What is the output of C program.? int main() { char ch='A'; ch=getchar(); putchar(ch); return 0; }//input= S
A) A
B) B
C) S
D) Compiler error
Answer [=]
C
Explanation:

getchar() reads one character from keyboard. putchar(ch) prints one character.

11) Choose a correct C statement.?
A) SCANF can accept all types of data from keyboard including numbers and strings
B) GETS can accept only one String of any length and any number of words. GETCHAR can accept only one character constant from keyboard.
C) SCANF can accept only single word Strings
D) All the above
Answer [=]
D
12) Choose a correct statement about C Escape Sequences.
A) \n produces new line.
B) \t produces one tab space (white spaces)
C) \b produces one Backspace
D) All the above
Answer [=]
D
13) What is the output of c program with %* operator.? int main() { char kh; scanf("%*c %c",&kh); putchar(kh); return 0; }//input=G H
A) G
B) H
C) A
D) Compiler error
Answer [=]
B
Explanation:

%* ignores the entered argument. So here G is ignored. 2nd argument, H is accepted by variable kh. Remember, You have to enter all arguments corresponding to each % symbol.

14) Choose a correct statement about C Escape Sequences.
A) \r produces one Carriage Return. \r does not take you to the next line. It takes cursor to only the beginning of same line.
B) \f produces form feed
C) \a produces Alert Sound or Beep Sound from PC motherboard speaker
D) All the above
Answer [=]
D
15) Choose a correct statement about C Escape Sequences.
A) \' outputs one Single Quote. Right Single Quote.
B) \" outputs one Double Quote.
C) \\ produces one Visible Back Slash \.
D) All the above
Answer [=]
D
16) What is a format specifier in C language.?
A) A format Specifier tells compiler to treat a variable value is predefined way.
B) Different format specifiers are used to print different type of data.
C) Format specifiers are used to write data to files in a formatted way.
D) All the above
Answer [=]
D
17) Choose a valid C format specifier.?
A) %d prints integer constants
B) %u prints unsigned integer constants
C) %ld prints signed long and %lu prints unsigned long constants
D) All the above
Answer [=]
D
18) Choose a correct statement about C format Specifiers.
A) %c prints unsigned or signed character constants.
B) %s prints string constants
C) %l or %L prints long constants.
D) All the above
Answer [=]
D
19) Choose a correct statement about format specifiers.
A) %f prints float constants with 6 digits of precision
B) %lf prints double constants
C) %Lf prints long double constants
D) All the above
Answer [=]
D
20) What does C format specifier %W.D represent.?
A) W represents total number of columns including precision digits.
B) D represents number of precision digits out of W columns.
C) Plus(+) before W.D is for Right Alignment. Minus(-) before W.D is for Left Alignment
D) All the above
Answer [=]
D