What is accomplished by the call to sprintf in the codefragment below?
char ans[20]
int num = 40;
sprintf(ans, "%d to %d", num, num +10);
A. Nothing, the function name ismisspelled
B. It returns as its value the string "40 to50"
C. It displays first the value of ans andthen the string "40 to 50" (without the quote marks)
D. It aborts because the value of ans isgarbage
E. None of the above

Respuesta :

Answer:

E. None of the above

Explanation:

char ans[20]

int num = 40;

sprintf(ans, "%d to %d", num, num +10);

This code fragment produce an error,because in 1st line of code char ans[20]  ,there is no semicolon after the line.As ans is undeclared ,the ide will produce an error as we use it in

                   sprintf(ans, "%d to %d", num, num +10);

If we put semicolon after the char ans[20] ,then it will not give error but also don't produce an output because for sprintf we should initialize the num and ans as of pointer type.

It is a condition for sprintf and num should be of string type.

C program

#include <stdio.h>

int main()  

{  

char ans[20];  

int num = 40;  

sprintf(ans, "%d to %d", num, num +10);  

return 0;  

}

Output  

No output  

(You can check this code on any ide for confirmation.)