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 (32) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (21) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (888) Python Coding Challenge (285) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

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