Home » Code Snippets » C/C++ Code Snippets

C++ - Print the string character by character using pointer

By: Priya Kaushal On 23 DEC 2016

Here, we will learn how to print string character by charter using pointer?

Another concept that we are using in this program is pointer arithmetic, here we will assign the address of string into the character pointer and prints the character by character by increasing pointer.

Consider the following program:

#include <iostream>

using namespace std;

int main()
{
	char name[]="Priya Kaushal";
	char *ptr=name;
	
	while(*ptr!=NULL){
		cout<<*ptr;
		ptr++;
	}
	
	cout<<endl;
	return 0;	
}

Output

Priya Kaushal

Remember, after reaching the end of the string ptr will no more point the same string.


COMMENTS



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.