Advertisement
#include<iostream>
using namespace std;
int main()
{
int size = 1000;
float ink_prc = 9.50;
short dist2 = 20;
char alpha_1 = 'a';
cout<< "The value in variable size is : " << size << "\n";
cout<< "The value in variable inc_prc is : " << ink_prc << "\n";
cout<< "The value in variable dist2 is : " << dist2 << "\n";
cout<< "The value in alpha_1 is : " << alpha_1 << "\n";
return 1;
}
The value in variable size is : 1000
The value in variable inc_prc is : 9.500000
The value in variable dist2 is : 20
The value in alpha_1 is : a
keywords | keywords | keywords | keywords |
---|---|---|---|
if | else | enum | extern |
float | do | for | goto |
double | int | long | near |
register | return | short | signed |
static | struct | switch | typedef |
union | unsigned | void | while |
auto | break | char | case |
far | const | continue | default |
namespace | explicit | operator | friend |
public | private | protected | virtual |
new | inline | mutable | typename |
dynamic_cast | reinterpret_cast | static_cast | const_cast |
this | throw | using | class |
true | bool | template | class |
catch | try | asm | wchar_t |
delete | false |
Advertisement
// declaring a constant in C++
#include<iostream>
using namespace std;
int main()
{
const int distance = 10;
cout<< "The value of constant distance is : " << distance;
return 0;
}
The value of constant distance is : 10
//Trying to modify a constant in C++
#include<iostream>
using namespace std;
int main()
{
const int kg = 1000;
kg = 2000;
cout<< "The value of kg is : " << kg;
return 0;
}
Cons.cpp: In function 'int main()':
Cons.cpp:10:7: error: assignment of read-only variable 'kg'
kg = 2000;
^~~~
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement