What will be the output??? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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 Antworten
+ 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