Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NETUncategorized

C Programming Questions and Answers – Formatted Input 

C Programming Questions and Answers – Formatted Input

 

1.What is the output of this C code?

#include <stdio.h>

int main()

{

int n;

scanf(“%d”, n);

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

return 0;

}

a) Compilation error

b) Undefined behavior

c) Whatever user types

d) Depends on the standard

View Answer

Answer:b

2.What is the output of this C code?

#include <stdio.h>

int main()

{

char *n;

scanf(“%s”, n);

return 0;

}

a) Compilation error

b) Undefined behavior

c) Nothing

d) None of the mentioned

View Answer

Answer:b

3.What is the output of this C code?

#include <stdio.h>

int main()

{

char n[] = “hellonworld!”;

char s[13];

sscanf(n, “%s”, s);

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

return 0;

}

a) hellonworld!

b) hello

world!

c) hello

d) hello world!

View Answer

Answer:c

4.What is the output of this C code?

#include <stdio.h>

int main()

{

short int i;

scanf(“%hd”, &i);

printf(“%hd”, i);

return 0;

}

a) Compilation error

b) Undefined behavior

c) Whatever user types

d) None of the mentioned

View Answer

Answer:c

5.What is the output of this C code?

#include <stdio.h>

int main()

{

short int i;

scanf(“%*d”, &i);

printf(“%hd”, i);

return 0;

}

a) Compilation error

b) Somegarbage value

c) Whatever user types

d) Depends on the standard

View Answer

Answer:b

6.What is the output of this C code?

#include <stdio.h>

int main()

{

short int i;

scanf(“%*hd”, &i);

printf(“%hd”, i);

return 0;

}

a) Compilation error

b) Somegarbage value

c) Whatever user types

d) Depends on the standard

View Answer

Answer:b

7.What is the output of this C code?

#include <stdio.h>

int main()

{

short int i;

scanf(“%h*d”, &i);

printf(“%hd”, i);

return 0;

}

a) Compilation error

b) Undefined behavior

c) Somegarbage value

d) Depends on the standard.

View Answer

Answer:a

8.Which of the following is NOT a delimiter for an input in scanf?

a) Enter

b) Space

c) Tab

d) None of the mentioned

View Answer

Answer:d

9.If the conversion characters of int d, i, o, u and x are preceded by h, it indicates?

a) A pointer to int

b) A pointer to short

c) A pointer to long

d) A pointer to char

View Answer

Answer:b

10.Which of the following doesn’t require an & for the input in scanf?

a) char name[10];

b) int name[10];

c) float name[10];

d) All of the mentioned

View Answer

Answer:a

11.Which of the following is an invalid method for input?

a) scanf(“%d%d%d”,&a, &b, &c);

b) scanf(“%d %d %d”, &a, &b, &c);

c) scanf(“Three values are %d %d %d”,&a,&b,&c);

d) None of the mentioned

View Answer

Answer:d

12.Which of the following represents the function for scanf?

a) void scanf(char *format, …)

b) int scanf(char *format, …)

c) char scanf(int format, …)

d) char *scanf(char *format, …)

View Answer

Answer:b

13.scanf returns as its value

a) Number of successfully matched and assigned input items

b) Nothing

c) Number of characters properly printed

d) Error

View Answer

Answer:a

14.What is the output of this C code?

#include <stdio.h>

void main()

{

int n;

scanf(“%d”, n);

printf(“%d”, n);

}

a) Prints the number that was entered

b) Segmentation fault

c) Nothing

d) Varies

View Answer

Answer:c

15.int sscanf(char *string, char *format, arg1, arg2, …)

a) Scans the string according to the format in format and stores the resulting values through arg1, arg2, etc.

b) The arguments arg1,arg2 etc must be pointers

c) Both a & b

d) None of the mentioned

View Answer

Answer:c

16.The conversion characters d, i, o, u, and x may be preceded by h in scanf to indicate

a) A pointer to short

b) A pointer to long

c) Nothing

d) Error

View Answer

Answer:a

17.What is the output of this C code (when 4 and 5 are entered)?

#include <stdio.h>

void main()

{

int m, n;

printf(“enter a number”);

scanf(“%d”, &n);

scanf(“%d”, &m);

printf(“%d\t%d\n”, n, m);

}

a) Error

b) 4 junkvalue

c) Junkvalue 5

d) 4 5

View Answer

Answer:d

Related Articles

Leave a Reply

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

Back to top button