Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

!expected identifier or ‘(’ before ‘int’

0 votes
asked Dec 3, 2019 by giri
int(int a,int b);
int main()
{
int a=2;
int b=3;
int c;
c=a+b;
printf('the value of c is');
}

8 Answers

0 votes
answered Dec 4, 2019 by anonymous
int(int a,int b);
int main()
{
int a=2;
int b=3;
int c;
c=a+b;
printf("the value of c is");
}
+1 vote
answered Dec 5, 2019 by Theodore Friedrich (290 points)
When the compiler sees "int(int a, int b)", it thinks you are trying to define a function. I'm not exactly sure what your purpose with that line is, but your code would run fine without. If your intent was to define a function, then you need to add a name and what ever you wanted it to execute. For example, if you wanted an "add" function, it would like like this:

int add(int a, int b) {

    return a + b;

}

If your initial intent was to have the line execute the "main" function, you have nothing to worry about. C++, which I am assuming you are using, executes "main" automatically after being compiled.

As a side note, your "printf" statement needs to use double quotes instead of single quotes. In C++ single quotes are used with "char" and double quotes are used with strings, unlike languages like Python that don't care which quotes you use.
commented Dec 5, 2019 by anonymous
It looks more like C considering printf instead of cout. And it should look like this:

printf("the value of c is %d", c);
commented Dec 9, 2019 by Theodore Friedrich (290 points)
Ah, my bad. I'm not familiar with C so I assumed it was C++.
0 votes
answered Dec 5, 2019 by TakeN

doing int(int a,int b); not in the currect way just simplly do int a,b; and it will run correctly !

0 votes
answered Dec 6, 2019 by likhith
we have to  made some changes to it here int(int a,int b) was declared before main its a syntax fault any function must have function name .Here no function name is declared and also there is single quotes in printf statement so it shows error.

corrected code is

#include<stdio.h>

int add(int a,int b);

int main()

{

int a=2;

int b=3;

int c;

c=a+b;

printf("the value of c is %d",c);

}
0 votes
answered Dec 7, 2019 by anonymous
int(int a, int b); wouldn't work since the compiler would go find that function which doesn't exist and has no name. Also, recommend to code the whole function before main() rather than after main since read top to bottom etc.

Format for before main():

void Addition(int a, int b){

int c = a + b;

printf("Value of c = %d", c);

}

Format for after main():

void Addition(int a, int b);

main(){

....

}

void Addition(int a, int b){

int c = a + b;

printf("Value of c = %d", c);
}

Also, in C, you'll need double quotes and to print out the variable, you need %d and the variable name.

#include <stdio.h>

int main()
{
int a=2;
int b=3;
int c;
c=a+b;
printf("the value of c is %d", c);

return 0;

}
commented Dec 8, 2019 by Donzy Botwe (440 points)
I think if you want to add numbers in c++ you do the following.

#include<iostream>

using namespace std;

int main()

{int a, b, c;

c=a+b;

cout<<c;

return 0;

}

with this you the programmer will have to type in the numbers yourself but you can also allow the user input marks to be added.

#include<iostream>

using namespace std;

int main()

{int a, b, c;

cout<<"Enter first number: ";

cin>>a;

cout<<"Enter second number: ";

cin>>b;

c=a+b;

cout<<c <<endl;

return 0;

}
0 votes
answered Dec 8, 2019 by Anmolnoor (240 points)

This is the what u want according to me 

#include<iostream>
int a,b;                
void main()                        
{
a=2;                          
b=3;                         
int c;                              
c=a+b;                                                                 
printf("the value of c is %d",c);   
}                                            

mistake's::::::

int(int a,int b);                  //here we trying to create global's variables just do as 

                                       //" int a,b;"
int main()                        //man function start...
{
int a=2;                          // error here multitime declaration & assigning the value of a 
int b=3;                          // error here multitime declaration & assigning the value of b
int c;                              //creating a local variable c
c=a+b;                           // compound expration for addition of a  and b then assigning value                                         // to c 
printf('the value of c is');   //here in printf expretion we use " insted of '  also u need to print                                              //the value of c which is ("%d",c) 
}                                            

/*

we use ' for the assigning a character to char type variable

if we use int main then we must return  a value in the end of the function

*/

0 votes
answered Dec 8, 2019 by Donzy Botwe (440 points)
#include<iostream>

using namespace std;

int main()

{int a, b, c;

cout<<"Enter first number: ";

cin>>a;

cout<<"Enter second number: ";

cin>>b;

c=a+b;

cout<<c <<endl;

return 0;

}
0 votes
answered Dec 8, 2019 by Donzy Botwe (440 points)
//A student of Bluecrest college in Ghana offering Bsc.IT in semester1
#include<iostream>
using namespace std;
int main()

{

int a=8;

int b=3;

int c;

c=a+b;

cout<<"The value of c is "<<c<<endl;
return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...