1.
Char str[10] = "A quick brown fox jumped over a lazy dog";puts(str);what will print?
Correct Answer
B. Error
Explanation
The given code will result in an error. This is because the size of the character array "str" is 10, but the assigned string "A quick brown fox jumped over a lazy dog" has a length of 42 characters (including the null terminator). Thus, the assigned string is too long to fit into the character array, causing a buffer overflow and resulting in an error.
2.
Char str1[10] "Hello!";int count1 = 0; while(str1[count1] != '\0') count1++;while loops will iterate until ______
Correct Answer
A. 10
Explanation
The while loop will iterate until the condition `str1[count1] != '\0'` is true. In this case, the loop will continue until the null character (`'\0'`) is encountered in the string `str1`. Since the string `str1` has a size of 10 and is initialized with the characters "Hello!", the loop will iterate 10 times before reaching the null character at the end of the string. Therefore, 10 is the correct answer.
3.
Gets() function is used to _____
Correct Answer
B. Get string from user
Explanation
The gets() function is used to get a string from the user. It reads characters from the standard input until a newline character is encountered and stores them in the string. This function is specifically designed for reading strings and should not be used for any other type of input.
4.
Strings in C are char array..
Correct Answer
A. True
Explanation
In C programming, strings are represented as character arrays. A string is a sequence of characters stored in consecutive memory locations, terminated by a null character '\0'. Therefore, the given statement "Strings in C are char array" is true.
5.
Char str[20] = "hello bee2a";printf("%s", str);Output = hello bee2a
Correct Answer
B. False
Explanation
The given code will output "hello bee2a" because it uses the printf function to print the string stored in the variable "str". Therefore, the correct answer is False.
6.
The ___ used in printf( ) is a format specification for printing out a string
Correct Answer
A. %s
Explanation
The format specification %s is used in the printf() function to print out a string. This means that when using %s in printf(), the corresponding argument should be a string that will be printed out.
7.
char *str[] = {"Hello Bee2A"}; *str = "Bye Bee2A"; puts(*str);Output = __________
Correct Answer
B. Bye Bee2A
Explanation
The code declares an array of character pointers named "str" and initializes it with the string "Hello Bee2A". Then, it assigns the address of the string "Bye Bee2A" to the first element of the array. Finally, the code prints the value at the address pointed to by the first element of the array using the puts() function. Therefore, the output will be "Bye Bee2A".
8.
char *str[] = {"2014"}; int year = atoi(str[0]); printf("___", year);What should be the format specifier?
Correct Answer
C. %d
Explanation
The correct format specifier in this case should be %d. This is because the variable "year" is an integer, and the printf function is used to print the value of an integer variable. The %d format specifier is used specifically for integers.
9.
char *str[1][2] = {"June", "6"}; printf("Month name is %s, which is %dth month of the year", ___ , ___ );What should be in the blanks to give the following outputMonth name is June, which is 6th month of the year
Correct Answer
A. Str[0][0], atoi(str[0][1]
Explanation
The correct answer is "str[0][0], atoi(str[0][1])".
In the given code, the array "str" is a 2D array of character pointers. It is initialized with two strings: "June" and "6".
In the printf statement, we need to print the first element of the first row of the array, which is "June", and the second element of the first row of the array, which is "6".
So, "str[0][0]" gives us "June", and "str[0][1]" gives us "6". The "atoi" function is used to convert the string "6" to an integer.
Therefore, the correct answer is "str[0][0], atoi(str[0][1])".
10.
We can store both int and char data in a char two-dimensional array?
Correct Answer
B. False
Explanation
A char two-dimensional array can only store characters, not integers. Integers would need to be converted to characters before being stored in the array. Therefore, it is not possible to store both int and char data in a char two-dimensional array.