CodesJava

Easy learning with example program codes

String in C


C Strings:

A sequence of characters, internally stored in the form of an array of characters is called as string.

Declaration of String:

In C, a string can be specified in two ways:

Character Array:

A string declared as an array, where each character represents an element of that array, is called as Character Array.

Syntax:

char array_Name[] = {char1,char2,char3………};

String Literal:

A string declared as an array, where the whole string represents a complete array, is called as String Literal.

Syntax:

char array_Name[] = “stringValue”

Example :

#include<stdio.h>  
#include <string.h>  
 
void main()
{    
char chr[]={'H', 'E', 'L', 'L', 'O', ' ', 'C', '\0'};    
char str[]="HELLO C";    
printf("String in form of character array: %s\n", chr);    
printf("String in form of string literal: %s\n", str);    
}

Output

String in form of character array: HELLO C
String in form of string literal: HELLO C
Posted in C   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki