C - Pointer

 

C Language

Pointer



Fill in the blanks

                            1.Pointer Points Address of another variable

                   2. &   Operator is used to obtain variable address

                   3. Write Pointer  Syntax datatype  *variablename=value;

                             4.int a=10; int *b=&a;   *b=  10  ,*b indicates value

                   5. int x=7; int *y=&x;  y indicates  address

                   6.To Print address using format  %u

Answer the following Question

                                                                    (4 marks)

                            1.Write a Program for Pointer to an Array.

#include<stdio.h>

#include<conio.h>

main()

{

int a[] ={0,1,2,3,4,5,6,7,8,9};

int i,*ptr;

ptr=a;

for(i=0;i<=9;i++)

{

printf("address =%u value=%d\n",ptr, *ptr);

ptr++;

}

getch();

}

                   2.Write a Program for Pointer to Function (or) swap Program using Pointer

#include<stdio.h>

#include<conio.h>

void swap(int  *x,int  *y)

{

int c;

c=*x;

*x=*y;

*y=c;

}

main()

{

int a,b;

clrscr();

printf("enter a,b\n");

scanf("%d%d",&a,&b);

printf("before swapping a=%d b=%d\n",a,b);

swap(&a,&b);

printf("after swapping a=%d b=%d\n",a,b);

getch();

}

No comments:

Post a Comment