C String

C string

string is group of characters. In c programming we can stored string as form of 1d array. null character "\0" are use to end of given string. syntax as follows.

  char variable_name[size];
Iteam overview
char keyword
variable_name Name of string
size size in form of number of character
Access specifier %s

For example

   char name[]="CODE";
    char store[5]={'C','O','D','E','\0'};
    char data[]={'C','O','D','E','\0'};
  
  /*Example of c strings*/
#include <stdio.h>
int main(){
  //declare and initialize of string array elements
  char data[]="CODE";
  printf("%s",data);//print string
}
C string Example

Output

CODE

Passing strings to function

we are send array in function parameter. look at this example

/*Example of c strings*/
#include <stdio.h>
void display(char arr[]){
  //print data
  printf("%s",arr);
}
int main(){
  //declare and initialize of string array elements
  char data[]="Hello Programmer";
  display(data);//passing array
}
Passing String
Hello Programmer

© 2019, regularcodes.com, All rights reserved