











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An explanation of pointers and reference passing in c programming language. It covers the concepts of passing pointers to functions, calling functions by reference, and using the const qualifier with pointers. The document also includes examples and program outputs.
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!
docsity.com
Pointers
docsity.com
docsity.com
.
void func ( int *pValue )
{
*pValue = 6;
}
void main ( )
{
int nValue = 5; printf(“nValue = %d\n“, nValue); func (&nValue ); printf("nValue = %d\n”, nValue);
}
// 5 gets printed, then 6 gets printed
`
nValue
5
pValue
00EF
00AA1 00EF
docsity.com
.
fig07_10.c (Part 1 of 2)
docsity.com
.
fig07_10.c (Part 2 of 2)
The string before conversion is: characters and Program Output $32. The string after conversion is: CHARACTERS AND $32.
docsity.com
.
fig07_11.c (Part 2 of 2)
Program Output The string is: print characters of a string
docsity.com
.
fig07_12.c
docsity.com
.
fig07_13.c
Program Output Compiling... FIG07_13.c D:\books\2003\chtp4\Examples \ch07\FIG07_13.c(15) : error C2166: l-value specifies const object Error executing cl.exe.
Changing *ptr is allowed – x is not a constant.
Changing ptr is an error – ptr is a constant pointer.
docsity.com
.
fig07_14.c
docsity.com
.
docsity.com
.
void swap ( int * , int * );
// function prototype
void main ( )
{
int x = 10 , y = 20 ;
printf(“Before calling swap \n”);
printf(“value of x=%d and y=%y \n”,x,y);
swap ( &x , &y ) ;
// function call
printf(“After calling swap \n”);
printf(“value of x=%d and y=%y \n”,x,y);
}
Swap using function
docsity.com
.
sizeof function
docsity.com