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.


Join The Discussion

Comments ( 7 )

  1. Hetshri Ved
    Hetshri Ved :
    7 months ago

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

  2. Om Chaturvedi
    Om Chaturvedi :
    1 year ago

    2 5 5 is the correct answer

  3. Vedant Kulkarni
    Vedant Kulkarni :
    2 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 :
    4 years ago

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

  5. Swathi Lakshmi
    Swathi Lakshmi :
    5 years ago

    cant understand

  6. Examveda
    Examveda :
    6 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 :
    6 years ago

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

Related Questions on Pointer