Chapter 11
Chapter 11
Chapter 11
NINT
/* Array Using Pointers */
#include<stdio.h>
#include<conio.h>
void main()
{
int b[100],*iptr;
iptr=&b;
clrscr();
printf("The initial value of iptr is %u\n",iptr);
iptr++;
printf("Incremented value of iptr is %u\n",iptr);
getch();
}
NINT
POINTERS IN ARRAYS Example 2
#include<stdio.h>
#include<conio.h>
void main()
{ 10
int arr[]={10,20,30,40};
int *ptr,i; 20
clrscr();
ptr=arr; // same as &arr[0]; 30
printf("\n The Result of the array is ");
for(i=0;i<4;i++) 40
{
printf("%d\n",*ptr);
ptr++;
}
getch();
}
NINT
Pointers as Function Arguments
When pointers are passed to a function :
The address of the data item is passed and thus the function
can freely access the contents of that address from within the
function
NINT
How the structure can be ptr=&st;
accessed by a pointer variable printf("\n display the details using
#include<stdio.h> structure variables");
#include<stdlib.h>
struct student printf( "%d %s %f", st.roll_no,
{ st.name, st.marks);
int roll_no;
char name[20]; printf("\n display the details using
float marks; pointer variables");
}st; printf( "%d %s %f",ptr->roll_no,
void main() ptr->name, ptr->marks);
{ }
struct student *ptr;
printf("\n \t Enter the record"); void print_rec(int r,char n[ ],float m)
printf("\n Enter the Roll Number"); {
scanf("%d",&st.roll_no); printf("\n You have Entered Following
record");
printf("\n Enter the Name"); printf("\n %d %s %f",r,n,m);
scanf("%s",st.name); }
scanf("%f",&st.marks);
Pointers & Strings
Using strings as pointers can be explained with the help of the
NINT