Stores the strings using pointer to char and char type array - C String

C examples for String:char array

Description

Stores the strings using pointer to char and char type array

Demo Code

#include <stdio.h>
#include <string.h>
int main()/*from  ww w  .  j  a v a 2  s.  c  o m*/
{
     char name[] = "book2s.com";
     char *pname = "book2s.com";
    
     printf("name: %s\n", name);
     printf("pname: %s\n", pname);
    
     strcpy(name, "book2s.c o m");
     pname = "book2s . c o m";
    
     printf("name: %s\n", name);
     printf("pname: %s\n", pname);
    
     printf("name (all eight bytes):  ");
     for(int i = 0; i < 8; i++) {
         printf("%c ", name[i]);
     }
    
     printf("\npname (all eight bytes):  ");
     for(int i = 0; i < 8; i++) {
         printf("%c ", *(pname + i));
     }
    
     return(0);
}

Result


Related Tutorials