Monday 9 April 2018

Pointer

In C language a pointer is a variable that points to or references a memory location in which data is stored. Each memory cell in the computer has an address that can be used to access that location so a pointer variable points to a memory location we can access and change the contents of this memory location via the pointer.

Pointer Declaration :
  A pointer is a variable that contains the memory location of another variable. The syntax is as shown below. You start by specifying the type of data stored in the location identified by the pointer. The asterisk (*) tells the compiler that you are type * variable name

Example :
 int *ptr;
float *string;

Address Operator :
  Once we declare a pointer variable we must point it to something we can do this by assigning to the pointer the address the address of the variable you want to point as in the following example :
ptr=#
   This places the address where num is stores into the variable ptr. If num is stored in memory 21260 address then the variable ptr has the value 21260.

Memory Space of int Pointer and long double pointer
  
Size of any type of pointer is independent of the data type which it is pointing i.e. size of pointer is always fixed. Size of any type (near) of pointer in C is two byte.

For example :
 #include<stdio.h>
 void main( )
{
int *p1;
long double *p2;
printf("%d %d", sizeof (p1) , sizeof (p2) );
}

Output :   2     2

Since both pointers int and long double are pointing to only first byte of int data and long double data respectively.
   
Hence both int pointer and long double pointer stores only address in 16 bits. Thus both of the them will occupy exactly equal memory spaces.

The size of void Pointer in C :
     
Size of any type of pointer in C is independent of data type which is pointer pointing i.e. size of all type pointer (near) in C is two byte either it is char pointer double pointer, function or null pointer. Void pointer is not exception of this rule and size of void pointer is also two byte.

0 Comments:

Post a Comment

Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (114) C (77) C# (12) C++ (82) Course (60) Coursera (176) coursewra (1) Cybersecurity (22) data management (11) Data Science (89) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (744) Python Coding Challenge (197) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses