ankitweblogic logo
W e b t u t o r i a l s

C Tutorial

Programing Approach

Algorithm

Flow Chart

Define C

Define Programming

C - Syntax

Compiler vs Interpreter

C - Variables

C - Keywords

C - Data Types

C - Comments

Turbo C - Shortcut keys

C - Operators

Hierarchy of Operators

Ex: Arithmetic Operator

C - Formatting Output

Constant Variable

C - Escape Sequence

C - if , switch

Ex: If condition

Ex: Inc / Dec Operator

C - loops

Ex: Loops

C - Nesting Of loops

Ex: Nested Loops

Jumping Statements

C - Arrays 1D

C - Arrays 2D

C - Sorting

ASCII Value

Character I/O Function

C - String Functions

Ex: Strings

Array of Strings

C - Math Functions

User-defined Function

Exercise Function

C - Types of Functions

Storage Class

C - Header Files

C - Preprocessor

C - Pointers

C - Structures

C - Typedef

C - File Handling

Ex: File Handling

Command Line Argument

MCQ

C - Pointers

A pointer is a variable whose value is the address of another variable. Like any variable, you must declare a pointer before storing any variable address.

int a=10;
int *p;
p=&a;

Example : Pointer

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int a=10;
    int *p;
    p=&a;

    printf("\nValue of A = %d", a); //10
    printf("\nAddress of A = %d",&a);
    printf("\nValue of p = %d",p);
    printf("\nAddress of P = %d",&p);
    printf("\nPointer of p = %d",*p); //10
}

Pointer can be use as an arrays.

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[10],i,*p;
    clrscr();
    printf("Enter 10 numbers : "); 
    for(i=0;i<=9;i++) 
	    scanf("%d",&a[i]);
    p=a;
    printf("\nFirst Value : %d",*p); 
    p=p+2;
    printf("\nAfter adding 2 in p : %d",*p); 
    p--;
    printf("\nAfter subtracting 1 in p : %d",*p); 
    getch();
}
Enter 10 numbers : 10
20
30
40
50
60
70
80
90
100
First Value : 10
After adding 2 in p : 30
After subtracting 1 in p : 20

Pointers to Pointers

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int a=10;
    int *p;
    p=&a;

    printf("\nValue of A = %d", a); //10
    printf("\nAddress of A = %d",&a);
    printf("\nValue of p = %d",p);
    printf("\nAddress of P = %d",&p);
    printf("\nPointer of p = %d",*p); //10
    int **q;
    q=&p;
    
    printf("\nValue of Q = %d",q);
    printf("\nAddress of Q = %d",&q);
    printf("\nPointer of Q = %d",**q); //10
	getch();
}