In C/C++ sizeof() operator is used to find size of a date type or variable. Expressions written in sizeof() are never executed.
Examples:
C
C
// 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;
}
Output: 4Even 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;
}
Output: a = 5, b = 4