+ 2
What is the output this code ?
#include <iostream> using namespace std; int abc(int a){ switch (a) { case 0: cout<<"one";break; case 1:cout<<"ten";break; default : cout<<"error"; } return 0; } int main(){ int c=3; c--; cout<<--c; cout<<abc(c); }
3 Answers
+ 4
your function return type is int so it must be return a value
return a or any integer value or make it void abc(). inside main you have declared one variable c which has value 3then ,--c which will be decreased by 1 after that in cout you print the value of --c this pre decrement operator will again decrease value by one so
1 will be printed o. screen next in last cout statement you calling function abc and pass c value as argument abc(1) in switch the case which have 1 will be executed so second case< ` ten `>will print it returning garbage value becz u using cout first ten printed then this cout<< cout<<<`ten`> which is garbage to avoid this remove cout where u calling function just write like this
abc(c)
+ 2
I corrected it. Thanks
+ 2
isming nima