Pointer declaration in C ,Address operator

Categories: C Programming language

In c 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 creating a pointer variable. Finally you give the name of the variable.

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 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.


/* A program to illustrate pointer declaration*/

main()

{

int *ptr;

int sum;

sum=45;

ptr=?

printf (“\n Sum is %d\n”, sum);

printf (“\n The sum pointer is %d”, ptr);

}

/* Program to display the contents of 

the variable their address using pointer variable*/

#include< stdio.h >

{

int num, *intptr;

float x, *floptr;

char ch, *cptr;

num=123;

x=12.34;

ch=’a’;

intptr=&x;

cptr=&ch;

floptr=&x;

printf(“Num %d stored at address %u\n”,*intptr,intptr);

printf(“Value %f stored at address %u\n”,*floptr,floptr);

printf(“Character %c stored at address %u\n”,*cptr,cptr);

}


Top Blogs
Introduction to Implementation of Queue using Linked List Published at:- Input and Output Functions in C Published at:- Importance of C Programming Language Published at:- How does C Programming Language Work Published at:- History of C Language : Introduction to C Programming Language Published at:- Benefits of C language over other programming languages Published at:- C Language Interview Question and Answers Published at:- Pointer declaration in C ,Address operator Published at:- C Program example: Input a number and print sum of its digits Published at:- What values are printed when we run following? Published at:- C Interview Questions And Answers Published at:- Learn C Programming language with example Published at:- C Memory Management ! Dynamic memory allocation Published at:- Structure in C: Introduction Published at:- Loops in C Published at:- Example of Function with no return type and no argument Published at:- Functions with arguments and no return values. Published at:- Functions with arguments and return values -C Examples Published at:- Functions that return multiple values -C Example Published at:- Types of Function in C ! Library Function in C ! User Defined Function In C ! Function Definition Published at:- C Functions ! What is a Function Published at:-
R4Rin Team
The content on R4Rin.com website is created by expert teams.