Machine-translated by Google. Questions are authored in English.
Top

Discussion

If the size of pointer is 32 bits What will be the output of the program ?

#include <stdio.h>

int main()
{
    char a[] = "Visual C++";
    char *b = "Visual C++";
    printf("%d, %d\n", sizeof(a), sizeof(b));
    printf("%d, %d", sizeof(*a), sizeof(*b));
    return 0;
}

 

  • A.10, 2
    2, 2
  • B.10, 4
    1, 2
  • C.11, 4
    1, 1
  • D.12, 2
    2, 2

Answer: C

Correct answer: 11, 4 1, 1

a is an array, so sizeof(a) is the whole thing: 10 characters plus the terminating null, 11. b is a pointer, so sizeof(b) is 32 bits, 4 bytes. Both *a and *b are single chars, so each is 1.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.