- 1
Could i write it like this ?
#include<iostream> using namespace std; main() { int a,b; a=10 b=10 int = a+b return 0; } without adding cout ? im completely new here!
11 Answers
+ 1
when u write int a,b; //it says to create two memory location of name a and b of the type integer.
a=10;
b=10; //it says to provide values 10 each to both the allocated memory.
int c=a+b; // it says to create a new memory allocation of integer type named c AND perform a sum operation.. and place the output to the c..
return 0; mean u don't want the function to return any output..
if u write here.. return c; then the function will hold an output
+ 1
you won't be able to see any output so cout is required.. wait there's error In it
+ 1
oh tnx bud! you were right!
+ 1
it would be like..
int main()
{
int a,b;
a=10;
b=10;
int c= a+b;
return 0;
}
+ 1
oh awesome...the above review really helped bruh!!! i followed you! do give me advice in my future comments !!!!
+ 1
for sure.. and thanx ^_^
+ 1
@Lival it isn't still correct.
//it should be like this
#include<iostream>
using namespace std ;
int main()
{
int a,b;
a=10;
b=10;
int c= a+b;
cout << c << endl; //endl isn't necessary but it's good to code like this
return 0;
}
Now its correct :)
0
sorry wait u missed semi colon and some syntax error
0
//it would be like..
#include<iostream>
int main()
{
int a,b;
a=10;
b=10;
int c= a+b;
cout<<sum;
return 0;
}
is this code correct ?
0
no here 'sum' is not defined..
And one line is missing "using namespace std;"
because the compiler don't find any memory allocated by variable "sum"
and you know u have save it output in variable "int c"
so the cout should be like cout<<c;
- 1
ahhh right! sorry im a complete newbie just started programmin 2 days ago