Arrays And Strings - Study Mode
[#106] How do you declare a two-dimensional integer array in C with 3 rows and 4 columns?
Correct Answer
(B) int arr[3][4]
[#107] How do you declare a string in C that can store up to 50 characters?
Correct Answer
(B) char str[50]
[#108] What is the output of printf("%d", sizeof("Hello"))
in C?
Correct Answer
(B) 6
Explanation
Solution: The printf("%d", sizeof("Hello")) statement in C is used to determine the size (in bytes) of the string literal "Hello" including the null terminator. In C, string literals are automatically null-terminated. The string "Hello" consists of 5 characters: 'H', 'e', 'l', 'l', 'o', and it also includes a null terminator ('x00') at the end to mark the end of the string. So, the total size of the string literal "Hello" is 6 bytes (5 characters + 1 null terminator). Therefore, the output of printf("%d", sizeof("Hello")) will be Option B: 6 because it's the size of the string in bytes, including the null terminator.
[#109] What is the correct way to declare and initialize a string in C?
Correct Answer
(A) char str[10] = "Hello"
[#110] Which of the following is the right syntax to copy n characters from the object pointed to by s2 into the object pointed to by s1?
Correct Answer
(A) void *memcpy(void *s1,const void *s2,size_t n)