0

Can we declare integer as data type?

int x=0; //ok integer x=0; // right or wrong? see the 2nd comment and ans it?

12th Jun 2018, 7:07 AM
Rahul Bavannavar
Rahul Bavannavar - avatar
12 Answers
+ 7
No, you can't declare an integer data type. Int means Integer Data type.
12th Jun 2018, 7:11 AM
Akash Pal
Akash Pal - avatar
+ 5
There an option you can define an integer as an int. You just wanted use integer in place of an int so you can define it. Just use #define integer int This will let you declare a variable with integer keyword. https://code.sololearn.com/cRg2HlPmzTPz/#cpp
12th Jun 2018, 7:20 AM
Akash Pal
Akash Pal - avatar
+ 3
no u cant declare integer as data type bcz integer is wrapper class U can use integer as like dis int a= Integer.parseInt(x);//as Integer.parseInt is a method hope u get it
12th Jun 2018, 7:12 AM
Harsh Agrawal
Harsh Agrawal - avatar
+ 2
Here's C++ example because it needed some messing around: https://code.sololearn.com/c8Er55KM8x8T/?ref=app
12th Jun 2018, 11:27 AM
BlazingMagpie
BlazingMagpie - avatar
+ 1
when we right integer then program works or not?
12th Jun 2018, 7:11 AM
Rahul Bavannavar
Rahul Bavannavar - avatar
+ 1
try yourself
12th Jun 2018, 7:13 AM
IMRAN HOSEN
IMRAN HOSEN - avatar
+ 1
Rahul Bavannavar no it did not work if u use integer it cause error as Integer is wrapper class
12th Jun 2018, 7:14 AM
Harsh Agrawal
Harsh Agrawal - avatar
+ 1
I Know this ans bro...it's question regarding interview
12th Jun 2018, 7:14 AM
Rahul Bavannavar
Rahul Bavannavar - avatar
+ 1
You can do it in some cases. In Java, Integer x = 0; would work because it will be automatically converted to Integer type. In fact, it's more efficient than Integer x = new Integer(0); In C++, you can make integer class and overload operators to convert to int and make single parameter constructor, then your code will be correct.
12th Jun 2018, 11:05 AM
BlazingMagpie
BlazingMagpie - avatar
+ 1
sometimes. example: int and Int32 mean the same thing in C#
12th Jun 2018, 5:07 PM
hinanawi
hinanawi - avatar
0
integer is not a data type.
12th Jun 2018, 7:10 AM
IMRAN HOSEN
IMRAN HOSEN - avatar
0
Rahul Bavannavar what do u mean with question regarding interview????
12th Jun 2018, 7:18 AM
Harsh Agrawal
Harsh Agrawal - avatar