You are here:

C++/C function

Advertisement


Question
What would the correct function be for the following in C and C++ and Java?

x = 21;
int x;
x = 42

I have written it as, is this correct for C++, can you assist with C and Java?

//Using endl for readability if actually used
x = 21;
cout << x << endl;
int x;
cout << x << endl;
x = 42;
cout << x << endl;


Answer
I dont understand what exactly you're trying to do. Are you using the first x before declaration? It is not possible then. You have to write something like:

int x;
x = 21;
cout << x << endl;
x = 42;
cout << x << endl;

Not sure if you're looking for this. In java, instead of cout you'd use:
System.out.println(x);  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Amit Kumar

Expertise

I can answer Cplusplus language and library questions, including STL, ACE, Boost. I have a good background in Mathematics.

Experience

Programming in CPP for about 8 years. Industry experience of 4 years.

Education/Credentials
Bachelors and Masters in Computer Science from Indian Institute of Technology Delhi.

©2016 About.com. All rights reserved.