What is the use of sizeof() operator in C?

The sizeof operator returns the size in bytes of its operand. Operand may be a variable or data type.

Here are few examples,

Example 1:

main()
 {
  char c;
 
  printf("%d,%d\n", sizeof c, sizeof(int)); /* returns 1, 4*/
 }

Example 2:

(main)
 {
	 struct 
	 {
	   int a;
	   int b;
	 }s;
 
	printf ("% d \ n", sizeof (s)); /* returns 8*/
	}

Example 3:

main()
 {
  short array [] = {1, 2, 3, 4, 5};
 
  short la = sizeof (array) / * returns 10 * /
 }
Chitra
Chitra

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in