Professional Documents
Culture Documents
Btech 1picu 5pointerstructureunionandintrotofilehandling 150122010700 Conver
Btech 1picu 5pointerstructureunionandintrotofilehandling 150122010700 Conver
1
Pointer, Structure, Union
&
Intro to File Handling
Course: BTECH
Subject: Programming In C Language
What is a pointer
The * and & operators bind more tightly than arithmetic operators so
y = *ip + 1; takes the value of the variable to which ip points, adds 1
and assigns it to y
Similarly, the statements *ip += 1; and ++*ip; and (*ip)++; all increment
the variable to which ip points. (Note that the parenthesis are
necessary in the last statement; without them, the expression would
increment ip rather than what it points to since operators like * and
++ associate from right to left.)
Pointer and Variable types
• The type of a pointer and its pointee must match
int a = 42;
int *ip;
double d = 6.34;
double *dp;
int main( )
{
int time, hours, minutes;
printf("Enter a time duration in minutes: ");
scanf ("%d", &time);
ConvertTime (time, &hours, &minutes);
printf("HH:MM format: %d:%02d\n", hours, minutes);
return 0;
}
An Exercise
• What is the output from this code?
void F (int a, int *b)
{ 4, 4
a = 7 ; 3, 7
*b = a ;
b = &a ;
*b = 4 ;
printf("%d, %d\n", a, *b) ;
}
int main()
{
int m = 3, n = 5;
F(m, &n) ;
printf("%d, %d\n", m, n) ;
return 0;
}
Pointers to struct
/* define a struct for related student data */
typedef struct student {
char name[50];
char major [20];
double gpa;
} STUDENT;
1. www.tutorialspoint.com/cprogramming/c_pointers.htm
2. www.cprogramming.com/tutorial/c/lesson6.html
3. pw1.netcom.com/~tjensen/ptr/pointers.html
4. Programming in C by yashwant kanitkar
5.ANSI C by E.balagurusamy- TMG publication
6.Computer programming and Utilization by sanjay shah Mahajan Publication
7.www.cprogramming.com/books.html
8.en.wikipedia.org/wiki/C_(programming_language)