The sizeof operator


sizeof will return the number of bytes reserved for a variable or data type.

The following code shows sizeof returning the length of a data type.


        /* How big is an int? expect an answer of 4. */
	
	main()
 	{
	   printf("%d \n", sizeof(int));
        }

sizeof will also return the number of bytes reserved for a structure.


        /* Will print 8 on most machines. */
	
        main()
	{
	  struct 
	  {
	    int a;
	    int b;
	  } TwoInts;
	
	printf("%d \n", sizeof(TwoInts));
	}
	

Finally, sizeof will return the length of a variable.


	main()
	{
	  char String[20];
	  
	  printf ("%d \n", sizeof String);
 	  printf ("%d \n", sizeof (String));
        }

In the example above I have printed the size of 'String' twice. This is to show that when dealing with variables, the brackets are optional. I recommend that you always place the brackets around the sizeof argument.


Examples:

Example 1 Data types.

Example 2 Data objects.


See also:

The strlen function.

Other operators

malloc function.


Top Master Index Keywords Functions


Martin Leslie

e5de27e940d00d8d504dfb96625fb654f641509'/>

path: root/drivers/usb/atm
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-12-04 12:50:51 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-04 12:50:51 -0800
commit3e5de27e940d00d8d504dfb96625fb654f641509 (patch)
treeb38dbbb5c36de40798435623d8db8736d9a26bb0 /drivers/usb/atm
parent0cb65c83304a341b9d09678448d7c8b550689531 (diff)
Linux 4.9-rc8
Diffstat (limited to 'drivers/usb/atm')