Examveda
Examveda

Determine Output:
main()
{
      char *str1 = "abcd";
      char str2[] = "abcd";
      printf("%d %d %d", sizeof(str1), sizeof(str2), sizeof("abcd"));
}

A. 2 5 5

B. 2 4 4

C. 8 5 5

D. 2 4 5

Answer: Option C

Solution(By Examveda Team)

In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable. In second sizeof the name str2 indicates the name of the array whose size is 5 (including the 'null' termination character). The third sizeof is similar to the second one.


This Question Belongs to C Program >> Pointer

Join The Discussion

Comments ( 7 )

  1. Hetshri Ved
    Hetshri Ved :
    2 years ago

    The answer is 2 5 5
    Can you explain how it 8 5 5

  2. Om Chaturvedi
    Om Chaturvedi :
    3 years ago

    2 5 5 is the correct answer

  3. Vedant Kulkarni
    Vedant Kulkarni :
    4 years ago

    They are using 64 bit compiler so the size of pointer variable is 8 byte in 64 bit compiler... Is it okay friends??

  4. Amit Tiwari
    Amit Tiwari :
    6 years ago

    the answer shoud be 2,5,5 as i run the code using tubo c compiler.

  5. Swathi Lakshmi
    Swathi Lakshmi :
    7 years ago

    cant understand

  6. Examveda
    Examveda :
    7 years ago

    Hello Shaik,
    sizeof(char *) is the size of the pointer, so normally 4 for 32-bit machine, and 8 for 64-bit machine.

  7. Shaik Salman
    Shaik Salman :
    7 years ago

    its answer is 8 5 5 just know I compile this program

Related Questions on Pointer