hot post

Arithmetic instruction in c (part 3)


Arithmetic instruction in c


In the c language learning series, we have learnt about what is operator in Arithmetic instruction in c and also learnt  about unary function. Today, we will study about 'sizeof()' function.

Arithmetic instruction in c

What is size of()


'sizeof()' is also a type of unary operators which tell us the size of different data type, variable and constant.

The right way to wright size of function is given below:

sizeof(data type)
sizeof(variable)
sizeof(constant)

Use of sizeof(data type) in Arithmetic instruction in c


Now let see how we can find the size of different different data type 
For example

#include<stdio.h>
#include<conio.h>
void main()
{
int =x;
clrscr();

x=sizeof(float)
printf("%d",x);
getch();
}

When we write 'float' then it tell the size of float which is '4'byte and if we write 'char' at the place of 'float' then it tell the size of char which is '1'byte

Use of sizeof(variable) in Arithmetic instruction in c

Now we learn the size of the different variable on the output screen with the help of 'sizeof()' unary operator

#include<stdio.h>
#include<conio.h>
void main()
{
int =x,y;

float=k;
double=d1
clrscr();

x=sizeof(y)
printf("%d",x);
getch();
}
When we run this program then it tells the size of 'y' which has int data type and we get '2' on the output screen. If we write 'd1' at the place of y then we get the size of double data type which is '8'byte.

Use of sizeof(constant) in Arithmetic instruction in c

#include<stdio.h>
#include<conio.h>
void main()
{
int =x,y,z;

clrscr();

x=sizeof(35)
y=sizeof(35.8)
z=sizeof('a')
printf("%d %d %d",x,y,z);
getch();
}

when we run this program then we get the following result:

The value of x will be '2'byte because it has an int data type.
The value of y will be '8'byte because it has a double data type.
The value of z will be '2' because the character constant converts into an integer. It is because we can not convert character constant in binary language so, there is a Technic in which each character constant has his specific code. Any character constant represents by their code.
We get 2,8,2 on the output screen.

I am trying my best to explain the c language to you, please stay with me and share this post and if there is any mistake then you comment on comment box

 Thanks for support

Post a Comment

0 Comments