Write a program to use & and sizeof operator and determine the size of integer and float variable.

integer and float
#include<conio.h>
#include<stdio.h>
main()
{
	int x=2;
	float y=2;
	printf("\n sizeof(x)=%d bytes",sizeof(x));
	printf("\n sizeof(y)=%d bytes",sizeof(y));
	printf("\n Address of x=%u and y=%u",&x,&y); //memory location is unsigned type//
	getch();
	
}

This program uses the sizeof operator and the & operator to determine the size and memory address of two variables, x and y.

The sizeof operator returns the size of the data type in bytes. In this program, x is an integer and y is a float, so sizeof(x) returns 4 and sizeof(y) returns 4.

The & operator returns the memory address of the variable. In this program, &x returns the memory address of x and &y returns the memory address of y. The memory addresses are printed using printf with the %u format specifier, as the memory addresses are unsigned integers.

The program outputs:

sizeof(x)=4 bytes
sizeof(y)=4 bytes
Address of x=memory_address_of_x and y=memory_address_of_y
Write a program to use & and sizeof operator and determine the size of integer and float variable.

Leave a Reply

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

Scroll to top