Find the output int x = 25; int calc(int x) { x++; cout<<x<<\" \"; return (x+1);
ID: 3697854 • Letter: F
Question
Find the output
int x = 25;
int calc(int x) {
x++;
cout<<x<<" ";
return (x+1);
}
int main ()
{
int x = 5;
cout<<x<<" "<<::x<<" "<<calc(3);
}
a. 4 4 4 5
b. 4 25 4 5
c. 4 5 25 5
d. 25 25 25 25
What is the error in the following code snippet?
void func(int a) {
a += 5;
return a;
}
int main()
{
func(3);
return 0;
}
a. Cannot change the value of variable a
b. The function cannot be called with a direct value such as 3
c. The function cannot return a value
d. Variable a must be declared in the function
why the answer is bc
please explain the reason
Explanation / Answer
#include <iostream>
using namespace std;
int x = 25;
int calc(int x)
{
x++;
cout<<x<<" ";
return (x+1);
}
int main ()
{
int x = 5;
cout<<x<<" "<<::x<<" "<<calc(3);
}
//OUTPUT : 4 5 25 5
//Answer : C
#include <iostream>
using namespace std;
void func(int a)
{
a += 5;
return a;
}
int main()
{
func(3);
return 0;
}
//Answer : c. The function cannot return a value
/*
func() is defined with the void return type but at the end of the function returning int value a;
this is error error: return-statement with a value, in function returning 'void'
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.