C – Pointer to String

Pointer to String:

  • A char* can points to a single character or a String.
  • Char* holds the base address.
  • We can process the strings using %s
  • To process character by character, we use %c
#include<stdio.h>
void main()
{
            char* s = “Harsha” ;
            printf(“%s \n”, s);
            printf(“%c \n”, s);
            printf(“%c \n”, *s);
            printf(“%c \n”, *(s+3));
            printf(“%c \n”, *s+3);
}
void main()
{
            char* s = “Sathya” ;
            printf(“%c \n”, *++s+2);
            printf(“%c \n”, *++s);
            printf(“%c \n”, *(s+2));
            printf(“%c \n”, *s–);
            printf(“%c \n”, *–s);
}
#include<stdio.h>
void main()
{
            char* str = “learnown”;
            printf(“%c\n”, *str++ + 3);
            printf(“%s\n”, ++str+2);
}
#include<stdio.h>
void main()
{
            char* str = “learnown”;
            printf(“%c\n” , *(str++ + 2)+3);
            printf(“%c\n” , *++str+2);
            printf(“%s\n” , –str-1);
}
#include<stdio.h>
void main()
{
            char* str = “learnown”;
            printf(“%c\n”,*((str– +2)+1)-3);
            printf(“%c\n”, *(–str + 3)-32);
            printf(“%c\n”,*(++str+2)+4);
}
#include<stdio.h>
void main()
{
            char sport[ ]= “cricket”;
            int x=1 , y;
            y=x++ + ++x;
            printf(“%c”,sport[++y]);
}
Scroll to Top