C Programming Structure And Pointer! Trivia Questions Test

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 Nauakrimilgai
N
Nauakrimilgai
Community Contributor
Quizzes Created: 12 | Total Attempts: 14,582
Questions: 15 | Attempts: 750

SettingsSettingsSettings
C Programming Structure And Pointer! Trivia Questions Test - Quiz

C programming is one of the most popular programming languages, and over the week we got to cover much about C programming structure and pointers. Do you recall that a pointer is a variable which points to the address of another variable of any data type? Take up this test and get to see how much you recall from class.


Questions and Answers
  • 1. 

    If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?

    • A.

      '.'

    • B.

      '&'

    • C.

      '*'

    • D.

      '->'

    Correct Answer
    D. '->'
    Explanation
    The '->' operator is used to access data members of a structure through a pointer variable. This operator is used when the variable is a pointer to a structure, allowing us to access the members of the structure using the pointer. It is used to dereference the pointer and access the members of the structure directly.

    Rate this question:

  • 2. 

    What will be the output of the program ?   int main() {     inti=3, *j, k;     j = &i;     printf("%d\n", i**j*i+*j);     return0; }

    • A.

      30

    • B.

      27

    • C.

      9

    • D.

      3

    Correct Answer
    A. 30
    Explanation
    j=&i implies *j=i;
    *j=3
    i**j=3*3=9
    i**j*i=9*3=27
    i**j*i+*j=27+3=30

    Rate this question:

  • 3. 

    What will be the output of the program?   int main() {     void *vp;     char ch=74, *cp="JACK";     int j=65;     vp=&ch;     printf("%c", *(char*)vp);     vp=&j;     printf("%c", *(int*)vp);     vp=cp;     printf("%s", (char*)vp+2);     return 0; }

    • A.

      JACK

    • B.

      JCK

    • C.

      J65K

    • D.

      JAK

    Correct Answer
    A. JACK
    Explanation
    The pointer always stores integer value so cp will store the memory address of the location where string "jack " is stored. VP = &ch; Will store address of ch in VP so while we print content in print it will print ASCII value of 74 i.e "J" VP = &j; It will assign address of j to VP again it will print ASCII value of 65 as "A" vp = cp; In this step cp is pointing to memory location where string jack is stored and we r incrementing it by two so it will point to "C" from sring "JACK" and since we have given %S in print so it will print content from c onward ie "CK"

    Rate this question:

  • 4. 

    What will be the output of the program ? int main() {     inti, a[] = {2, 4, 6, 8, 10};     change(a, 5);     for(i=0; i<=4; i++)         printf("%d, ", a[i]);     return 0; } change(int *b, int n) {     int i;     for(i=0; i<n; i++)         *(b+1) = *(b+i)+5; }

    • A.

      7, 9, 11, 13, 15

    • B.

      2, 4, 6, 8, 10

    • C.

      3, 1, -1, -3, -5

    • D.

      2, 15, 6, 8, 10

    Correct Answer
    D. 2, 15, 6, 8, 10
    Explanation
    *(b+1) = *(b+i)+5;
    1. i = 0 => *(b+1) ie 4 is replaced by *(b+0)+5 ie 2+5
    2. i = 1 => *(b+1) ie 4 is replaced by *(b+1)+5 ie 4+5
    3. i = 2 => *(b+1) ie 4 is replaced by *(b+2)+5 ie 6+5
    4. i = 3 => *(b+1) ie 4 is replaced by *(b+3)+5 ie 8+5
    5. i = 4 => *(b+1) ie 4 is replaced by *(b+4)+5 ie 10+5

    Rate this question:

  • 5. 

    What will be the output of the program ? int main() { char *str; str = "%s"; printf(str, "K\n"); return 0; }

    • A.

      Error

    • B.

      K

    • C.

      No Output

    • D.

      %s

    Correct Answer
    B. K
    Explanation
    printf(str, "K\n"); is replaced with printf("%s" , "K\n");
    (since str = "%s";)

    So it will print K.

    Rate this question:

  • 6. 

    Which of the following function is used to find the first occurrence of a given string in another string?

    • A.

      Strchr()

    • B.

      Strrchr()

    • C.

      Strstr()

    • D.

      Strnset()

    Correct Answer
    C. Strstr()
    Explanation
    The function strstr() is used to find the first occurrence of a given string in another string. It searches for the first occurrence of the specified substring within a larger string and returns a pointer to the first character of the found substring. This function is commonly used in string manipulation and searching operations.

    Rate this question:

  • 7. 

    What will be the output of the program ?   int main() {     char p[] = "%d\n";     p[1] = 'c';     printf(p, 65);     return 0; }

    • A.

      A

    • B.

      A

    • C.

      65

    • D.

      C

    Correct Answer
    B. A
    Explanation
    In this program, the character array p initially contains the format specifier "%d\n". Then, the character at index 1 of the array p is changed to 'c', so the array becomes "%c\n", indicating that it will print a character.
    When printf(p, 65) is executed, it interprets the format specifier as "%c\n", so it expects a character argument. The integer value 65 is interpreted as the ASCII code for the character 'A'. Therefore, the output of the program will be:
    A

    Rate this question:

  • 8. 

    Trace the output. int main() {     char str[] = "basic";     char *s = str;     printf("%s ", s++ +3);     printf("%s",s);     return 0; }

    • A.

      C c

    • B.

      Ic asic

    • C.

      Asic sic

    • D.

      C basic

    Correct Answer
    B. Ic asic
    Explanation
    printf("%s ", s++ +3); -> ic since (s++ +3) and s++ is post increment but +3 just print string from 'i'. It ll not increment the pointer to 3. printf("%s",s); here after incrementing (s++) It ll print ''asic''.

    Rate this question:

  • 9. 

    What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

    • A.

      ((((a+i)+j)+k)+l)

    • B.

      (((a+i)+j)+k+l)

    • C.

      *(*(*(*(a+i)+j)+k)+l)

    • D.

      *((a+i)+j+k+l)

    Correct Answer
    C. *(*(*(*(a+i)+j)+k)+l)
    Explanation
    The correct answer is *(*(*(*(a+i)+j)+k)+l). This expression is equivalent to referring to the array element a[i][j][k][l]. The expression starts with (a+i) which accesses the i-th element of the array a. Then, *(a+i) gives the pointer to the i-th element. Next, *(a+i)+j accesses the j-th element of the i-th element. This process continues with the addition of k and l, accessing the k-th and l-th elements respectively. Finally, the expression *(*(*(*(a+i)+j)+k)+l) dereferences the pointer to obtain the value of the array element a[i][j][k][l].

    Rate this question:

  • 10. 

    What will be the output of the program ?   int main() {     int i;     char a[] = "\0";     if(printf("%s", a))         printf("The string is empty\n");     else         printf("The string is not empty\n");     return 0; }

    • A.

      The string is empty

    • B.

      The string is not empty

    • C.

      No output

    • D.

      0

    Correct Answer
    B. The string is not empty
    Explanation
    The function printf() returns the number of characters printed on the console. char a[] = "\0"; The variable a is declared as an array of characters and it initialized with "\0". It denotes that the string is empty. if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero). Hence the if the condition is failed. In the else part it prints "The string is not empty".

    Rate this question:

  • 11. 

    Are the expression *ptr++ and ++*ptr are same?

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    *ptr++ increments the pointer and not the value,
    ++*ptr increments the value being pointed by ptr .

    Rate this question:

  • 12. 

    If the size of integer is 4bytes, What will be the output of the program? int main() { int arr[] = {12, 13, 14, 15, 16}; printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0])); return 0; }

    • A.

      10, 2, 4

    • B.

      20, 2, 2

    • C.

      20, 4, 4

    • D.

      16, 2, 2

    Correct Answer
    C. 20, 4, 4
    Explanation
    The output of the program will be "20, 4, 4". The sizeof(arr) will give the total size of the array which is 20 bytes (5 integers, each taking 4 bytes). The sizeof(*arr) will give the size of the first element of the array, which is an integer and takes 4 bytes. The sizeof(arr[0]) will give the size of a single element in the array, which is also an integer and takes 4 bytes.

    Rate this question:

  • 13. 

    What will be the output of the program ? int main() {     char str[] = "India\0\is Best\0";     printf("%d\n", strlen(str));     return 0; }

    • A.

      10

    • B.

      6

    • C.

      5

    • D.

      11

    Correct Answer
    C. 5
    Explanation
    The function strlen returns the number of characters in the given string. Therefore, strlen(str) becomes strlen("India") contains 5 characters. A string is a collection of characters terminated by '\0'. The output of the program is "5"

    Rate this question:

  • 14. 

    What will be the output of the program ? int main() {     printf(5+"Good Morning\n");   return 0; }

    • A.

      M

    • B.

      Morning

    • C.

      Good Morning

    • D.

      Good

    Correct Answer
    B. Morning
    Explanation
    printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.
    Hence the output is "Morning"

    Rate this question:

  • 15. 

    What will be the output of the program ? int main() {     char str1[] = "Hello";     char str2[] = "Hello";     if(str1 == str2)         printf("Equal\n");     else         printf("Unequal\n");     return 0; }

    • A.

      Equal

    • B.

      Error

    • C.

      Unequal

    • D.

      None of above

    Correct Answer
    C. Unequal
    Explanation
    if(str1 == str2) here the address of str1 and str2 are compared. The addresses of both variables are not the same. Hence the if the condition is failed. At the else part it prints "Unequal".

    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
  • Feb 21, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Jul 11, 2012
    Quiz Created by
    Nauakrimilgai
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.