Learn C++ Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I declare and initialize a string in C++?

Asked by Last Modified  

Follow 2

Please enter your answer

Experienced Computer trainer having worked in IT sector for 20 years.

Declaring a string in C is as simple as declaring a one-dimensional array. Below is the basic syntax for declaring a string. char string_name; Example for initializing the string. char str = "GeeksforGeeks"; char str = "GeeksforGeeks"; char str = { 'G','e','e','k','s','f','o','r','G','e','e','k','s','\0'}; char...
read more

Declaring a string in C is as simple as declaring a one-dimensional array. Below is the basic syntax for declaring a string.

char string_name[size];

Example for initializing the string.

char str[] = "GeeksforGeeks";

char str[50] = "GeeksforGeeks";

char str[14] = { 'G','e','e','k','s','f','o','r','G','e','e','k','s','\0'};

char str[] = { 'G','e','e','k','s','f','o','r','G','e','e','k','s','\0'};

char string_name[size];

In the above syntax str_name is any name given to the string variable and size is used to define the length of the string, i.e the number of characters strings will store.


There is an extra terminating character which is the Null character (‘\0’) used to indicate the termination of a string that differs strings from normal character arrays.


read less

Make your future bright with me!!!

to create a string we first declare it, then we can store a value in it. cout << "This is a string." << endl; In order to use the string data type, the C++ string header <string> must be included at the top of the program.

Related Questions

I am interested to enter IT field. But I am not from IT background. My qualification is BBM. I am planing to start with C and C++ course, but i don't have much idea about it. Can some one please let me know what is best course to start with.
if u really have interset in IT filed u better learn .net, core java, spring java, python programming languages than c and c++. but u don't know the basics programming language better going for c and c++ learning course.
Which language is best, C, C++, Python or Java?
If you want to learn any languages C#, Java, ect. then must to learn C, C++ language as these are base or language to be strong in language skills. C++ is improved version of C language. C#, Java, J# and etc. which are improved version of C++.
0 0
please tell me the best book for c programming language
LET US C by Yashwant Kanetkar. This book is very useful to improve the practical Knowledge. For Theory - Programming in C by Balagurusamy
Is C#, C++, Python, or JS better for game development?
All languages good for gamjng. But you can make 3d games in c# uaing unity software and it's very very interesting to work on it.
0 0
How C++ is different from C language?
++ is an increment operator c++ is nothing but adding a new feature to the existing c language. Here, new feature is nothing but object oriented principles.

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Working with C/C++ applications
Inorder to learn C and C++ programming languages one can work with various editors available.To name a few are the most popular one is turbo c++, DEV C++, Eclipse, NetBeans. Here are the screen shots...

Set 0 To Kth Bit In A Variable
The following code snippet Set 0 to Kth Bit in an variable #include int UnsetBitValue(int n, int k);int main(){ printf("%d\n\n",UnsetBitValue(255,6)); return 0;}// Set kth bit to zeroint UnsetBitValue(int...

C++ Program-Factorial
//Header files #include<iostream.h>#include<conio.h> //Main function void main(){ int num,i; long factorial=1; //Function for clearing screen clrscr(); cout<< "Enter a number:";...

Tress And Its Traversal
Depth First Traversals:(a) Inorder (Left, Root, Right) : 4 2 5 1 3(b) Preorder (Root, Left, Right) : 1 2 4 5 3(c) Postorder (Left, Right, Root) : 4 5 2 3 1 Trees are one of the data structures like...

Efficient Learning Strategies
Type your notes after class Write your notes onto flashcards - Scrabble -Make posters Review flashcards while walking, at gym, etc. Dog-ear pages in the reading where you can find...

Recommended Articles

Introduction C++ is an excellent programming language and many of the applications are written in C++ language. It has generic, object-oriented & imperative programming features, and also provides facilities for low-level memory manipulation. Successor of C language, it is an OOP (object oriented programming) language...

Read full article >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

Read full article >

Looking for C++ Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you

Looking for C++ Language Classes?

The best tutors for C++ Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C++ Language with the Best Tutors

The best Tutors for C++ Language Classes are on UrbanPro

Book a Free Demo

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more