Formatted Input and Output in C

Formatted Input and Output in C

University

10 Qs

quiz-placeholder

Similar activities

CULTURAL PRACTICES

CULTURAL PRACTICES

University

10 Qs

Research Methods

Research Methods

12th Grade - University

14 Qs

HTML Quiz - Codedu

HTML Quiz - Codedu

University

15 Qs

Quiz 1 - Intro to C

Quiz 1 - Intro to C

University

10 Qs

HTML, CSS QUIZ

HTML, CSS QUIZ

University

10 Qs

KNOWLEDGE GAME

KNOWLEDGE GAME

University

11 Qs

ICS 31/8/2020

ICS 31/8/2020

University

10 Qs

Mindzone Season-3

Mindzone Season-3

University

15 Qs

Formatted Input and Output in C

Formatted Input and Output in C

Assessment

Quiz

Other

University

Hard

Created by

Harvinder Kaur

Used 9+ times

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What will be the output of the above code if a=123456789245?

123456789245

Compilation error

1234567892

No output

Answer explanation

Using %10d in scanf restricts input to a maximum of 10 digits.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

The syntax of printf() function is printf(“control string”, variable list) ;


what is the prototype of the control string?

%[flags][.precision][width][length]specifier

%[flags][length][width][.precision]specifier

%[flags][width][.precision][length]specifier

%[flags][.precision][length][width]specifier

Answer explanation

The prototype of control string is %[flags][width][.precision][length]specifier. Each control string must begin with % sign

3.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will be the output of the following C code?


char str[] =”Too Good”;

printf(“\n %7s”,str);

Too Good

Too G

Too Go

Too

Answer explanation

The complete string “Too Good” is printed. This is because if data needs more space than specified, then printf overrides the width specified by the user.

4.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

What will be the output of the following C code?


printf(“\n Output: %5d \t %x \t %#x”, 234,234,234);

Output:

234EA0xEA

Output:

00234 EA 0xEA

Output:

234 EA 0xEA

ERROR

Answer explanation

The control character \t is used to provide gap between the words. %5d – the width of the string is set to 5, characters are printed after being padded with blank spaces.%x, %#x is additional specifiers for octal and hexadecimal values.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Select the right explanation to the given code.


printf(“%*. *f”, 5,4,5700);

the minimum field width has to be 4, the precision is given to be 5, and the value to be displayed is 5700

the minimum field width is 5, the precision is 4, and the value to be displayed is 5700

compile error

run-time error

Answer explanation

The minimum field width and precision specifiers are usually constants. They can also be provided by arguments to printf(). This is done by using * modifier as shown in the given code.

6.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will be the output for the given code ?


printf (“\n The number is %07d”,1212);

The number is 0001212

The number is 1212

The number is 1212

The number is 1212000

Answer explanation

0 in the above code is Flags. The number is left-padded with zeros(0) instead of spaces.

7.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What happens when zero flag is used with left justification?

data is padded with zeros

zero flag is ignored

data is padded with blank spaces

will give error

Answer explanation

Zero flag is not considered when used with left justification because adding zeros after a number changes its value.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?