Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NETUncategorized

C Programming Questions and Answers – Formatted Output

C Programming Questions and Answers – Formatted Output

1.What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 10, j = 2;

printf(“%d\n”, printf(“%d %d “, i, j));

}

a) Compile time error

b) 10 2 4

c) 10 2 2

d) 10 2 5

View Answer

Answer:d  

2.What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 10, j = 3;

printf(“%d %d %d”, i, j);

}

a) Compile time error

b) 10 3

c) 10 3 some garbage value

d) Undefined behaviour

View Answer

Answer:c 

3.What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 10, j = 3, k = 3;

printf(“%d %d “, i, j, k);

}

a) Compile time error

b) 10 3 3

c) 10 3

d) 10 3 somegarbage value

View Answer

Answer:c  

4.What is the output of this C code?

#include <stdio.h>

int main()

{

char *s = “myworld”;

int i = 9;

printf(“%*s”, i, s);

}

a) myworld

b) myworld(note: spaces to the left of myworld)

c) myworld (note:followed by two spaces after myworld)

d) Undefined

View Answer

Answer:b

5.What is the output of this C code?

#include <stdio.h>

int main(int argc, char** argv)

{

char *s = “myworld”;

int i = 3;

printf(“%10.*s”, i, s);

}

a) myw

b) myworld(note:2 spaces before myworld)

c) myworld (note:2 spaces after myworld)

d) myw(note:6 spaces after myworld)

View Answer

Answer:d

6.What is the difference between %e and %g?

a) %e output formatting depends on the argument and %g always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional.

b) %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument.

c) No differences

d) Depends on the standard

View Answer

Answer:b

7.Escape sequences are prefixed with.

a) %

b) /

c) ”

d) None of the mentioned

View Answer

Answer:d

8.What is the purpose of sprintf?

a) It prints the data into stdout

b) It writes the formatted data into a string

c) It writes the formatted data into a file

d) Both a and c

View Answer

Answer:b

9.The syntax to print a % using printf statement can be done by.

a) %

b) %

c) ‘%’

d) %%

View Answer

Answer:d 

10.What does this statement printf(“%10s”, state); means?

a) 10 spaces before the string state is printed

b) Print empty spaces if the string state is less than 10 characters

c) Print the last 10 characters of the string

d) None of the mentioned

View Answer

Answer:b 

11.What are the Properties of first argument of a printf functions?

a) It is defined by user

b) It keeps the record of the types of arguments that will follow

c) There may no be first argument

d) None of the mentioned

View Answer

Answer:b 

12.What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 10, j = 2;

printf(“%d\n”, printf(“%d %d “, i, j));

}

a) Compile time error

b) 10 2 4

c) 10 2 2

d) 10 2 5

View Answer

Answer:d 

13.What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 10, j = 3;

printf(“%d %d %d”, i, j);

}

a) Compile time error

b) 10 3

c) 10 3 some garbage value

d) Undefined behaviour

View Answer

Answer:c 

14.What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 10, j = 3, k = 3;

printf(“%d %d “, i, j, k);

}

a) Compile time error

b) 10 3 3

c) 10 3

d) 10 3 somegarbage value

View Answer

Answer:c

15.What is the output of this C code?

#include <stdio.h>

int main()

{

char *s = “myworld”;

int i = 9;

printf(“%*s”, i, s);

}

a) myworld

b) myworld(note: spaces to the left of myworld)

c) myworld (note:followed by two spaces after myworld)

d) Undefined

View Answer

Answer:b

16.What is the output of this C code?

#include <stdio.h>

int main(int argc, char **argv)

{

char *s = “myworld”;

int i = 3;

printf(“%10.*s”, i, s);

}

a) myw

b) myworld(note:2 spaces before myworld)

c) myworld (note:2 spaces after myworld)

d) myw(note:6 spaces after myworld)

View Answer

Answer:d 

17.What is the difference between %e and %g ?

a) %e output formatting depends on the argument and %g always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional.

b) %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument.

c) No differences

d) Depends on the standard

View Answer

Answer:b 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button