I think almost every Computer Science Engineer wants to learn programming languages. Most basic high level languages which freshers try to learn are C++ and Java. There are a lot of chances of mixing up of syntax and implementation of a concept in these languages because each of them have their own features. Here is a humble effort from my side to carve out the basic differences in implementation of basic concepts and features of both the languages.
I will be describing few of the differences in my every post. Any suggestions and queries are also invited.
Here is the dose for the day.
Statement
% can be used only for integers in C++ but in Java it can also be used for floating point numbers.
int a=65,b=7;
float f=7.7;
cout<<(a%b)<<endl;
cout<<(f%b)<<endl;//error
This code gives error and last line does not compiles.
int a=55,b=7;
float f=54.5f;
System.out.println(a%b);
System.out.println(f%b);
Output is
6
5.5
Thanks all for your time. We will continue with 'Difference between C++ and Java' series in next post. Any queries and suggestions are invited in comments and through e-mails.
I will be describing few of the differences in my every post. Any suggestions and queries are also invited.
Here is the dose for the day.
- Use of % (modulo) operator
Statement
% can be used only for integers in C++ but in Java it can also be used for floating point numbers.
- C++
int a=65,b=7;
float f=7.7;
cout<<(a%b)<<endl;
cout<<(f%b)<<endl;//error
This code gives error and last line does not compiles.
- Java
int a=55,b=7;
float f=54.5f;
System.out.println(a%b);
System.out.println(f%b);
Output is
6
5.5
Thanks all for your time. We will continue with 'Difference between C++ and Java' series in next post. Any queries and suggestions are invited in comments and through e-mails.
No comments:
Post a Comment