sizeof (int) will tell you (in bytes). It's often 2, 4 or 8 bytes.
When we call a function in C++ by passing the values as arguments, it is called call by value. e.g #include<iostream.h> #include<conio.h> int add(int,int); int main() { int a,b,c; cout<<"Enter numbers."; cin>>a>>b; c=add(a,b); cout<<"Sum : "<<c; return 0; } int add(int a,int b) { int c; c=a+b; return c; }
#include<iostream> int main() { int var=42; // store the value 42 in a variable named var. return(0); }
int min (int a, int b, int c) {if (a
void main() { int *x = malloc(sizeof(int) * 10); }
The main difference is that int values are treated as being integers whereas char values are treated as being character codes. Thus if you output a char with value 65 you will get the symbol 'A', but if you output an int with the value 65 you will get the value 65 instead. In order to output the symbol 'A' you would have to cast the int to a char.
To round off to the nearest integer... double a = {some value}; a = (int) (a + 0.5); To round off to the nearest hundredth... double a = {some value}; a = (int) (a * 100. + 0.5) / 100.; These are just two examples.
An example may help: int x= 3; Here 'int' is a type, 'x' is a variable with the type, and '3' is a value of the type.
int max (int a, int b) { return a<b?b:a; } int max3 (int a, int b, int c) { return max (max (a, b), c); }
void is used by functions that do not return a value. For example: // This function returns an integer, which you can use in other functions int addTwoNumbers(int a, int b) { return(a + b); } // This function does not return a value, so we declare it as a void void printSum(int a, int b) { cout << a << " + " << b << " = " << addTwoNumbers(a, b) << endl; // Note that attempting to return a value here will cause an error. }
struct point { int x; int y; };
double mean(int list[], int arraySize) { double result=0; for(int i=0; i<arraySize; ++i ) result += list[i]; return(result/size); }
int main() { int x = 40 + 2; }