String is an important part of programming. Strings are the array of character types. In competitive exams like GATE also it is an important topic. So let’s discuss some key points about string and then we will proceed to some questions that will help you clear your concepts about string.
String in a programming language can be stored in two different ways. They are using character array (char str[size]) and using a pointer that will point to the string (char * ch = “Hello”). There are some important things related to the use of the character array and pointer to a string. They are
Let’s see some practice questions
Predict the output of the
char name = "TutorialsPoint"; char *ptr = name; cout<<++ptr;
The value of pointer is increased by one so it will start printing from index 1.
char name = "TutorialsPoint"; int length = strlen(name); for(int i=length;i>1;i--) printf("%c", name[i]);
Printing reverse of the string by starting from length to 1.
char c = "LearnProgrammingAtTutorialsPoint"; char *p =c; printf("%s", p + c - c+1) ;
Here we have created a pointer to the string and there increase the values of the pointer by some index which print the rest of the string.