C Tutorial
Character pointer (*ptr) is used to hold the address of character in the array.
#include<stdio.h> void main() { char desc[] = "codingpointer.com"; char *ptr; // assign address of first character in the string ptr = desc; //iterates all the characters upto '\0'. while(*ptr != '\0') { printf("%c", *ptr); ptr++; } }Output:
$ cc print-string-using-pointer.c $ ./a.out codingpointer.com
#include<stdio.h> void main() { char desc[] = "codingpointer.com"; printf("%s", desc); }Output:
$ cc print-string-using-pointer.c $ ./a.out codingpointer.com
#include<stdio.h> void main() { char desc[20]; printf("Enter string: "); scanf("%s", desc); printf("desc: %s", desc); }Output: ,pre> $ cc print-string-using-pointer.c $ ./a.out Enter string: codingpointer.com desc: codingpointer.com[
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page