+ 3

Can you please explain the code and tell me the output. Actually when I tried to compile the code it shows error.

#include <iostream> using namespace std; int f(int k) {k++; return k;} int main() { int K{2}; k++; f(k); cout <<k; } this question is coming in c++ challenges

22nd Jul 2017, 10:40 AM
Tamil Selvan
Tamil Selvan - avatar
7 Respuestas
+ 13
@ Tamil int k {2}; k++ // now value of k is 3 f (k) cout <<k // prints 3 bcos the value of f (k) not assigned to any variable sorry i don't see that "explain"
22nd Jul 2017, 12:33 PM
khadeeja Shamna
khadeeja Shamna - avatar
+ 12
you used capital k at main ()
22nd Jul 2017, 10:46 AM
khadeeja Shamna
khadeeja Shamna - avatar
+ 12
value assigning to k
22nd Jul 2017, 10:56 AM
khadeeja Shamna
khadeeja Shamna - avatar
+ 4
thank you @khadeeja
22nd Jul 2017, 10:48 AM
Tamil Selvan
Tamil Selvan - avatar
+ 4
plz explain the code to me. what is the meaning of k{3}
22nd Jul 2017, 10:50 AM
Tamil Selvan
Tamil Selvan - avatar