+ 23

char *a ="coding"; char *b=(++a)+3; cout << b;???

i don't understand this, can someone give some explanation?

1st Dec 2016, 1:22 AM
Jobelle
Jobelle - avatar
9 Respuestas
+ 3
you're right saeid, i think it writes cout<<*b;
1st Dec 2016, 5:51 PM
Nima Moradi
Nima Moradi - avatar
+ 2
@vikas i'm sure that i get at least one run from this code and the answer was "n" ;)
1st Dec 2016, 5:16 PM
Nima Moradi
Nima Moradi - avatar
+ 2
if 'cout<<b' the output is "ng" but if 'cout<<*b' the output is "n"
1st Dec 2016, 5:48 PM
Saeed
Saeed - avatar
+ 2
all these *chars acts as an array the ' *a ' initially indicates/ points the first charactr of the string and as the *a gets incremented the memory address is increased. as like in arrays. also these are defined in chars so output is also a char not a string so 'n' is the right answer
18th May 2017, 12:39 PM
U L Knw Me soon😉😋
U L Knw Me soon😉😋 - avatar
+ 1
the output is "ng" bcuz you assign the address of n to b. and when you print b then it will print from n to last character of the string i.e. g.
1st Dec 2016, 3:32 AM
vikas
+ 1
hey @nima, before saying anyone wrong.....first you should prove yourself correct............can you please copy this code and run it on this app sololearn.............you'll get your ans
1st Dec 2016, 5:08 PM
vikas
+ 1
b points to a + 4 implies cout << b prints 'ng'
28th Dec 2016, 5:48 PM
Suvaditya
Suvaditya - avatar
- 1
the output is "n" because you assigned "a" from second character(++a) to end to "b" and you want print a character in the index "3" from this "oding", that is 'n'
1st Dec 2016, 1:30 AM
Nima Moradi
Nima Moradi - avatar
- 1
you're wrong @vikas
1st Dec 2016, 8:16 AM
Nima Moradi
Nima Moradi - avatar