Search Header Logo

Formatted Input and Output in C

Authored by Harvinder Kaur

Other

University

Used 9+ times

Formatted Input and Output in C
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

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.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?