312 Programming and Data Structures
Destination before memcpy: Today is Sunday
Destination after memcpy : Tomorrow is Sunday
Explanation The function memccpy () works similarly as in the previous program. It copies the
source string to the destination string. Both the strings are displayed.
9.37 Write a program to display the string through their pointer.
# include <stdio.h>
# include <conio.h>
void mainO
{
char *c,*m;
cm"Central Processing Unit";
nt»' lath Co- Procresser*;
clrscrO
printf ( " 'c ' is pointing the string '% s'n",c);
printf ( " 'm ' is pointing the string '% s'n ,m);
getcheO;
I
OUTPUT:
Y is pointing the string 'Central Processing Unit7
'm' is pointing the stringJMath Co- Processor'
Explanation In the above program two strings are initialized to the character pointers ' c ' a n d 'm'.
When printed using "%s" control string in p r in t f () statement, entire strings are displayed.
9.10 VOID POINTERS
Pointers can also be declared as void type. Void pointers cannot be dereferenced without explicit type
conversion. This is because, being void the compiler cannot determine the size of the object that the
pointer points to, Though void pointer declaration is possible, void variables declaration is not al
lowed. Thus, the declaration v o id p displays an error message " Size of'p' is unknown or zero." after
compilation.
9.38 Write a program to declare a void pointer. Assign address of int, float, and char
variables to the void pointer using type casting method. Display the contents of
various variables.
# include <stdio.h>
# include <conio.h>
// void p o in te r 3 / /
int p;
floa t d;
char c;
void *pt « &p;
/ * pt points to p */
void main (void)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.34.39