Monday, October 4, 2010

Pointer and character type array


Like integer array pointer can also points to character array.
Here is a sample C program :

#include< stdio.h >
void main ()
{
char str []="This is a string";
char *str2=str;
clrscr ();
printf ("%s\n", str);
printf ("%s\n", str2);
str2++;
printf ("%s\n", str2);
 getch ();
 }



Another such program using C Language

#include< stdio.h >
void main ()
{
char str [20];
char *str2;
clrscr ();
printf ("Enter any string:-");
scanf ("%s", str);
str2=str;
printf ("String displayed through the variable:-%s\n", str);
printf ("String displayed through the pointer:-%s\n", str2);
printf ("\nString displayed character wise through the pointer:-\n");
while (*str2!='\0')
{
printf ("%c\n", *str2);
str2++;
}
 getch ();
 }


No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner