Quick links: C-Tricks HR Interview Que. Code Snippets C Programs C++ Programs Java Programs PHP Examples

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;	
}

Sponsored Links



Output

Priya Kaushal

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


COMMENTS

Solved programs


Sponsored Links


Most viewed pages


Featured posts
C Tips and Tricks

Keywords (like Linux, Java, Oracle etc) used in this website are the trademarks of their respective owners/company. This website is not affiliated to any company. The tutorials are designed by includehelp Team with the help of well known books and other online resources. These Tutorials are free for all, for learning purposes only. Enjoy learning:)
Copyright © 2015 - 2016. All Rights Reserved.