Welcome !!

NICETECHVIDYA

Tutorials

Web Designs

You are welcome to Aptech Designers, designed by Pratik from Nepal.

Creativity is my passion. Logo describes your details about company.

Graphics Design needs vision to create yours unique digital concept.

Responsive and All Browser Compatible Dynamic Web Layouts our target.

Home Python C Language J A V A Our Courses
This WebSite is under Construction....

Friday, 11 March 2022

56.Pointers, Characteristics of a variable

 

Pointers:

 

Computer memory:

RAM is the primary, main or conventional memory of computer.

It is used to store the data, instructions and intermediate results.

It is a volatile memory, looses its data on termination of program or function.

The total memory is divided into number of bytes.

Each byte is divided into 8 bits.

Every byte is identified with a number called address (It is a positive number).

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Characteristics of a variable:

Any variable of any type has three characteristics that is the name, value and the address.

Name is an identifier by which allocated memory is located in a program

Value is the data stored in the variable in a binary format.

Address is the byte number from where memory of the variable is allocated.

 

Example:

int first=2345;

float price=14.560000;

 

 

 

 

 

 

 

 

 

 

 


Address of (&):

When a variable is declared then the memory of which is allocated in the free memory or heap of computer.

Any variable of any type may take one or more bytes of memory but the first byte number is considered as the address of memory allocation. It is always a positive number (unsigned). %u is used to print the address.

Address of (&) is an operator used to get the address of any specified variable.

 

Example1:

#include<stdio.h>

void main()

{

int first=2345;

clrscr();

printf("Value of  first %d",first);

printf("\n Address of first %u",&first);

getch();

}

 

Output:

Value of first 2345

Address of first 65492

 

Note: Address of a variable changes program to program and computer to computer.

 

Example2:

#include<stdio.h>

void main()

{

int x=45,y=52;

clrscr();

printf("x=%d",x);

printf("\ny=%d",y);

printf("\nAddress of x %u",&x);

printf("\nAddress of y %u",&y);

getch();

}

 

Output:

x=45

y=52

Address of x 65492

Address of y 65494

 

 

 

Example explained:

x, y are a series of variables of integer type, the memory allocation of which allocates in contagious memory allocations.

 

Value at (*):

It is a special operator in C language used to access the value of a memory allocation through the address indirectly. So it is called indirect operator.

Accessing the value through the address using value at (*) operator is called indirection.

 

Example:

#include<stdio.h>

void main()

{

int x=45;

clrscr();

printf("x=%d",x);

printf("\nx=%d",*(&x));

getch();

}

 

Output:

x=45

x=45

 

Example explained:

Value at (address of x) 65492 is 45

It is accessing the value indirectly through the address.

0 comments:

Post a Comment