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 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: 4
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; } |
Output: 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 contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Is sizeof for a struct equal to the sum of sizeof of each member?
- Difference between sizeof(int *) and sizeof(int) in C/C++
- Functions that are executed before and after main() in C
- Implement Your Own sizeof
- Operands for sizeof operator
- Do not use sizeof for array parameters
- How to find size of array in C/C++ without using sizeof ?
- sizeof() for Floating Constant in C
- sizeof operator in C
- Difference between strlen() and sizeof() for string in C
- Why does sizeof(x++) not increment x in C?
- Written version of Logical operators in C++
- Relational Database from CSV Files in C
- Difference between std::set vs std::vector in C++ STL

