C sizeof

  • sizeof is a unary operator in C.

    Output:

    The terms in sizeof() are stored in stack. Firstly the 3 is inserted then 3.0999999. Thus as we know stack is a LIFO (last in first out) data structure. Therefore sizeof operator will give a size of last item i.e, 3.0999999. As 3.0999999 is of double data type, it returns size of double i.e, 8.
  • Here in the first printf, address array elements are always an integer. So that it return value of integer data type i.e, 4 bytes. In the second printf statement, it returns the number of elements in arr and ‘\0’
  • In first statement, null consider as a string. In the second statement, nothing means zero. So there are two elements zero and \0. Therefore it return number of elements.

Difference between sizeof and strlen

Ankit Wasankar

Senior Java Developer
Java 11 | Microservices | Reactjs | SQL

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.