Knowee
Questions
Features
Study Tools

Multi Choice Type QuestionWhich statement correctly reads a string into a character array using scanf?Marks : 1Negative Marks : 0Answer herechar str[50]; scanf("%s", &str);char str[50]; scanf("%s", str);char str[50]; scanf("%c", &str);char str[50]; scanf("%c", str);

Question

Multi Choice Type QuestionWhich statement correctly reads a string into a character array using scanf?Marks : 1Negative Marks : 0Answer herechar str[50]; scanf("%s", &str);char str[50]; scanf("%s", str);char str[50]; scanf("%c", &str);char str[50]; scanf("%c", str);

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct statement to read a string into a character array using scanf is:

char str[50]; scanf("%s", str);

This is because in C, the name of an array is a pointer to the first element of the array. Therefore, you don't need to use the '&' operator to get the address. The '%s' format specifier is used to read a string.

Similar Questions

Multi Choice Type QuestionHow do you correctly initialize a string to store "C programming"?Marks : 1Negative Marks : 0Answer herechar str[13] = "C programming";char str[] = {"C programming"};char str[] = "C programming";Both char str[] = {"C programming"}; and char str[] = "C programming"; are correctClear

Multi Choice Type QuestionWhich function is used to convert a string to an integer in C?Marks : 1Negative Marks : 0Answer hereatoiitoaatofatol

How can you read a string with spaces using scanf?Marks : 1Negative Marks : 0Answer herescanf("%s", str);scanf("[^\n]", str);scanf(" %[^\n]", str);scanf("%[ ]", str);

Select the correct answerFor single character input and output, Which functions are used?Optionsscanf() and printf()getchar() and putchar()input() and output()None of the given options are correct

Multi Choice Type QuestionHow is a null pointer represented in C?Marks : 1Negative Marks : 0Answer hereNULL0-11

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.