+ 2

What will be the output???

#include<iostream> using namespace std; int main() { char *s = "c++"; cout<<s<<" "; s++; cout<<s<<" "; }

6th Jun 2017, 7:41 AM
Rachit Tripathi 😘
Rachit Tripathi 😘 - avatar
7 Respostas
+ 7
#include <iostream> using namespace std; //change void main () to int main (void) int main (void){ char *s ="c++"; /* Interpreting as char array s[0] = 'c' s[1] = '+' s[2] = '+' */ cout<<s<<" "; //prints the entire char array ie "c++" /* by default s points to the first character in the char array ie s[0] s++ moves the pointer to the next character in the char array ie s[1] */ s++; cout<<s<<" "; //prints "++" }
6th Jun 2017, 8:07 AM
à€Šà„‡à€”à„‡à€‚à€Šà„à€° à€źà€čà€Ÿà€œà€š (Devender)
à€Šà„‡à€”à„‡à€‚à€Šà„à€° à€źà€čà€Ÿà€œà€š (Devender) - avatar
+ 7
it will show an error.....you are trying to store string in char....
6th Jun 2017, 7:58 AM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 7
void main 😒
6th Jun 2017, 8:02 AM
jay
jay - avatar
+ 6
Your code has no meaning at all.
6th Jun 2017, 8:04 AM
đŸ‡ș🇾 Anatoli🇧đŸ‡ȘđŸ‡ȘđŸ‡ș ,
đŸ‡ș🇾 Anatoli🇧đŸ‡ȘđŸ‡ȘđŸ‡ș , - avatar
+ 5
hmmm jay is right... change it to int main and return 0
6th Jun 2017, 8:03 AM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 4
ok guyss... changed void to int
6th Jun 2017, 8:07 AM
Rachit Tripathi 😘
Rachit Tripathi 😘 - avatar
+ 3
So the answer will be "c++ ++" ??
6th Jun 2017, 8:10 AM
Rachit Tripathi 😘
Rachit Tripathi 😘 - avatar