Right Click to Search

Thursday, January 14, 2025

Initializing String / Charater Array in C Programming


Ways of Initializing String

Way 1 :Unsized Array and Character
  • Unsized Array : Array Length is not specified
  • Array length is Automatically calculated by Compiler
  • Individual Characters are written inside pair of braces with comma as seperator
  • Note : NULL Character should be written
char name [] = {'P','R','I','T','E','S','H','\0'};
Way 2 : Directly initialize String Variable
  • Assign String to variable of type Character Array
  • No need to write NULL('\0') character at end
  • NULL Character is appended Automatically
char name [ ] = "PRITESH";
Way 3 : Character Pointer Variable
  • Declare Character variable of pointer type so that it can hold the base address of "String"
  • Base address means address of first array element i.e (address of name[0] )
  • NULL Character is appended Automatically
char *name = "PRITESH";

Related Topic : 

Tags / Keywords : | , ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates