Skip to content
Related Articles

Related Articles

Anything written in sizeof() is never executed in C

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 02 Oct, 2017

In C/C++ sizeof() operator is used to find size of a date type or variable. Expressions written in sizeof() are never executed.


// C program to demonstrate that the
// expressions written in sizeof() are
// never executed
#include <stdio.h>
int main(){
    // The printf in sizeof is not executed
    // Only the return type of printf is 
    // considered and its size is evaluated
    // by sizeof,
    int a = sizeof(printf("hey"));
    printf("%d", a);
    return 0;


Even if we assign a value inside sizeof(), the changes are not reflected.

// One more C program to demonstrate that 
// the expressions written in sizeof() are
// never executed
#include <stdio.h>
int main() {
    int a = 5;
    int b = sizeof(a = 6);
    printf("a = %d,  b = %d\n", a, b);
    return 0;

a = 5, b = 4

This article is contributed by Nishu Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!