+ 1
What is the output of given code? Please explain too.
char* p="thisQuiz"; p+=2; char c=1 + *p; cout<<c;
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
+ 3
@dw0x, I liked how you explained it, it's nice to have company in answering question, why delete your answer mate?
+ 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 : )
+ 3
@Shahnawaz Alam you're welcome : )
+ 2
@Ipang @dw0x Thank you