Quiz 7 (Improvement) And Assignment 4 - Bee-2a *

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Aamirakbar2
A
Aamirakbar2
Community Contributor
Quizzes Created: 1 | Total Attempts: 57
Questions: 10 | Attempts: 57

SettingsSettingsSettings
Quiz 7 (Improvement) And Assignment 4 - Bee-2a * - Quiz


Strings, Strings Pointers


Questions and Answers
  • 1. 

    Char str[10] = "A quick brown fox jumped over a lazy dog";puts(str);what will print?

    • A.

      A quick brown fox jumped over a lazy dog

    • B.

      Error

    • C.

      A quick br

    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.

    Rate this question:

  • 2. 

    Char str1[10] "Hello!";int count1 = 0;    while(str1[count1] != '\0')        count1++;while loops will iterate until ______

    • A.

      10

    • B.

      9

    • C.

      Until the condition is true

    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.

    Rate this question:

  • 3. 

    Gets() function is used to _____

    • A.

      Get any kind of data from user

    • B.

      Get string from user

    • C.

      Do job exactly like scanf() function

    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.

    Rate this question:

  • 4. 

    Strings in C are char array..

    • A.

      True

    • B.

      False

    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.

    Rate this question:

  • 5. 

    Char str[20] = "hello bee2a";printf("%s", str);Output = hello bee2a

    • A.

      True

    • B.

      False

    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.

    Rate this question:

  • 6. 

    The ___ used in printf( ) is a format specification for printing out a string

    • A.

      %s

    • B.

      %d

    • C.

      %c

    • D.

      %f

    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.

    Rate this question:

  • 7. 

     char *str[] = {"Hello Bee2A"}; *str = "Bye Bee2A"; puts(*str);Output = __________

    • A.

      Hello Bee2A

    • B.

      Bye Bee2A

    • C.

      Error

    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".

    Rate this question:

  • 8. 

     char *str[] = {"2014"}; int year = atoi(str[0]); printf("___", year);What should be the format specifier?

    • A.

      %s

    • B.

      %c

    • C.

      %d

    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.

    Rate this question:

  • 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

    • A.

      Str[0][0], atoi(str[0][1]

    • B.

      Str[0][1], atoi(str[1][0]

    • C.

      Str[0][0], atoi(str[0][0]

    • D.

      Str[1][1], atoi(str[1][1]

    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])".

    Rate this question:

  • 10. 

    We can store both int and char data in a char two-dimensional array?

    • A.

      True

    • B.

      False

    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.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • May 29, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 12, 2014
    Quiz Created by
    Aamirakbar2
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.