+ 1

What is the output of given code? Please explain too.

char* p="thisQuiz"; p+=2; char c=1 + *p; cout<<c;

2nd Jan 2018, 12:48 PM
Shahnawaz Alam
Shahnawaz Alam - avatar
5 Answers
+ 4
#include <iostream> using namespace std; int main() { // Declare char pointer that points to a // string literal containing "thisQuiz" char* p="thisQuiz"; // Move the pointer offset two bytes forward, // Output: "isQuiz" if you go cout << p; // Output: 'i' if you go cout << *p; p+=2; // Declare a char whose value would be the // character pointed by *p, added by one. // At this point *p points to 'i', so by // adding 1 to 'i' will result in 'j' char c=1 + *p; // Output the value of char variable c. // Output: 'j' cout << c; return 0; } Hth, cmiiw
2nd Jan 2018, 2:58 PM
Ipang
+ 3
@dw0x, I liked how you explained it, it's nice to have company in answering question, why delete your answer mate?
2nd Jan 2018, 3:05 PM
Ipang
+ 3
@dw0x, Duplicate question = Not Ok Similar answer = Ok Still, I think if one gives related/relevant, or good answer, there's no problem at all mate. Sometimes similar answers look different in the OP perspective, one maybe easier to understand than the others : )
2nd Jan 2018, 4:01 PM
Ipang
+ 3
@Shahnawaz Alam you're welcome : )
3rd Jan 2018, 4:35 AM
Ipang
+ 2
@Ipang @dw0x Thank you
3rd Jan 2018, 4:33 AM
Shahnawaz Alam
Shahnawaz Alam - avatar