answersLogoWhite

0


Best Answer

That' what sizeof is good for.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you find out the size of int for a particular compiler?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Which is type casting operator in java?

It means to explicitly convert to a certain type.double a = 5.0;int b;b = (int) a;The (int) is the explicit typecast in this case, but any type can be used, including a user-defined type (i.e., a class name). If you omit it, the compiler will complain, because when you convert a double to an int, precision may be lost. If you include it, you override this compiler check - you basically tell the compiler that you know what you are doing.It means to explicitly convert to a certain type.double a = 5.0;int b;b = (int) a;The (int) is the explicit typecast in this case, but any type can be used, including a user-defined type (i.e., a class name). If you omit it, the compiler will complain, because when you convert a double to an int, precision may be lost. If you include it, you override this compiler check - you basically tell the compiler that you know what you are doing.It means to explicitly convert to a certain type.double a = 5.0;int b;b = (int) a;The (int) is the explicit typecast in this case, but any type can be used, including a user-defined type (i.e., a class name). If you omit it, the compiler will complain, because when you convert a double to an int, precision may be lost. If you include it, you override this compiler check - you basically tell the compiler that you know what you are doing.It means to explicitly convert to a certain type.double a = 5.0;int b;b = (int) a;The (int) is the explicit typecast in this case, but any type can be used, including a user-defined type (i.e., a class name). If you omit it, the compiler will complain, because when you convert a double to an int, precision may be lost. If you include it, you override this compiler check - you basically tell the compiler that you know what you are doing.


What is the difference between initialisation and definition in C programming?

Variable-declaration is: extern int x; extern double y; extern char a; Variable-definition is: int x; static double y; auto char a; Variable-definition with initialization is: int x = 1; static double y= 2.3; auto char a = 'w';


Menu driven program for selection sort bubble sort and insertion sort in c?

#include<iostream> #include<time.h> #include<iomanip> #include<string> void swap(int& x, int& y) { x^=y^=x^=y; } void bubble_sort(int* A, int size) { while(size) { int n=0; for(int i=1; i<size; ++i) { if(A[i-1]>A[i]) { swap(A[i-1], A[i]); n=i; } } size=n; } } void insertion_sort(int* A, int size) { for(int i=1; i<size; ++i) { int value=A[i]; int hole=i; while( hole && value<A[hole-1] ) { A[hole]=A[hole-1]; --hole; } A[hole]=value; } } void selection_sort(int* A, int size) { for(int i=0; i<size-1; ++i) { int j=i; for(int k=i+1; k<size; ++k) if(A[k]<A[j]) j=k; if( i!=j ) swap(A[i],A[j]); } } void sort(int* A, int size, int sort_type) { switch(sort_type) { case(0): bubble_sort( A, size ); case(1): insertion_sort( A, size ); case(2): selection_sort( A, size ); } } int* copy_array(int* A, int size) { int* copy=new int[size]; memcpy(copy, A, size*sizeof(int)); return(copy); } void print_array(int* A, int size, char* prompt) { std::cout<<prompt<<"\t"; for(int i=0; i<size; ++i) std::cout<<std::setw(2)<<A[i]<<" "; std::cout<<std::endl; } int get_rand(int range_min=0, int range_max=RAND_MAX) { return((int) ((double)rand() / (RAND_MAX + 1) * ((range_max + 1) - range_min) + range_min)); } int input_char(std::string prompt, std::string input) { char ch; do { std::cout<<prompt<<": "; std::cin>>ch; } while(input.find(ch)==std::string::npos); return(input.find(ch)%(input.size()/2)); } int main() { srand((unsigned) time(NULL)); int size = get_rand( 10, 80); if( int* A = new int[size] ) { for( int i=0; i<size; ++i ) A[i]=get_rand( 1, size ); int choice=input_char("Please select a sorting method:\n[B]ubble, [I]nsert, [S]election", "bisBIS"); std::cout<<"You chose "; switch(choice) { case(0): std::cout<<"bubble"; break; case(1): std::cout<<"insertion"; break; case(2): std::cout<<"selection"; break; } std::cout<<" sort...\n"<<std::endl; print_array( A, size, "Before sorting" ); sort(A, size, choice); print_array( A, size, "After sorting" ); delete [] A; } return(0); }


Get size of int using sizeoff?

printf ("sizeof (int) = %d\n", (int)sizeof (int));


Long int size?

sizeof (long int) usually 4 or 8

Related questions

Which is type casting operator in java?

It means to explicitly convert to a certain type.double a = 5.0;int b;b = (int) a;The (int) is the explicit typecast in this case, but any type can be used, including a user-defined type (i.e., a class name). If you omit it, the compiler will complain, because when you convert a double to an int, precision may be lost. If you include it, you override this compiler check - you basically tell the compiler that you know what you are doing.It means to explicitly convert to a certain type.double a = 5.0;int b;b = (int) a;The (int) is the explicit typecast in this case, but any type can be used, including a user-defined type (i.e., a class name). If you omit it, the compiler will complain, because when you convert a double to an int, precision may be lost. If you include it, you override this compiler check - you basically tell the compiler that you know what you are doing.It means to explicitly convert to a certain type.double a = 5.0;int b;b = (int) a;The (int) is the explicit typecast in this case, but any type can be used, including a user-defined type (i.e., a class name). If you omit it, the compiler will complain, because when you convert a double to an int, precision may be lost. If you include it, you override this compiler check - you basically tell the compiler that you know what you are doing.It means to explicitly convert to a certain type.double a = 5.0;int b;b = (int) a;The (int) is the explicit typecast in this case, but any type can be used, including a user-defined type (i.e., a class name). If you omit it, the compiler will complain, because when you convert a double to an int, precision may be lost. If you include it, you override this compiler check - you basically tell the compiler that you know what you are doing.


How can you get size of datatype?

like this: sizeof(int); replace int with the kind of data you want to find the size of. of course, to be able to do anything with this size data, you'll have to store it into a variable or display it or something.


What is the difference between initialisation and definition in C programming?

Variable-declaration is: extern int x; extern double y; extern char a; Variable-definition is: int x; static double y; auto char a; Variable-definition with initialization is: int x = 1; static double y= 2.3; auto char a = 'w';


Menu driven program for selection sort bubble sort and insertion sort in c?

#include<iostream> #include<time.h> #include<iomanip> #include<string> void swap(int& x, int& y) { x^=y^=x^=y; } void bubble_sort(int* A, int size) { while(size) { int n=0; for(int i=1; i<size; ++i) { if(A[i-1]>A[i]) { swap(A[i-1], A[i]); n=i; } } size=n; } } void insertion_sort(int* A, int size) { for(int i=1; i<size; ++i) { int value=A[i]; int hole=i; while( hole && value<A[hole-1] ) { A[hole]=A[hole-1]; --hole; } A[hole]=value; } } void selection_sort(int* A, int size) { for(int i=0; i<size-1; ++i) { int j=i; for(int k=i+1; k<size; ++k) if(A[k]<A[j]) j=k; if( i!=j ) swap(A[i],A[j]); } } void sort(int* A, int size, int sort_type) { switch(sort_type) { case(0): bubble_sort( A, size ); case(1): insertion_sort( A, size ); case(2): selection_sort( A, size ); } } int* copy_array(int* A, int size) { int* copy=new int[size]; memcpy(copy, A, size*sizeof(int)); return(copy); } void print_array(int* A, int size, char* prompt) { std::cout<<prompt<<"\t"; for(int i=0; i<size; ++i) std::cout<<std::setw(2)<<A[i]<<" "; std::cout<<std::endl; } int get_rand(int range_min=0, int range_max=RAND_MAX) { return((int) ((double)rand() / (RAND_MAX + 1) * ((range_max + 1) - range_min) + range_min)); } int input_char(std::string prompt, std::string input) { char ch; do { std::cout<<prompt<<": "; std::cin>>ch; } while(input.find(ch)==std::string::npos); return(input.find(ch)%(input.size()/2)); } int main() { srand((unsigned) time(NULL)); int size = get_rand( 10, 80); if( int* A = new int[size] ) { for( int i=0; i<size; ++i ) A[i]=get_rand( 1, size ); int choice=input_char("Please select a sorting method:\n[B]ubble, [I]nsert, [S]election", "bisBIS"); std::cout<<"You chose "; switch(choice) { case(0): std::cout<<"bubble"; break; case(1): std::cout<<"insertion"; break; case(2): std::cout<<"selection"; break; } std::cout<<" sort...\n"<<std::endl; print_array( A, size, "Before sorting" ); sort(A, size, choice); print_array( A, size, "After sorting" ); delete [] A; } return(0); }


Get size of int using sizeoff?

printf ("sizeof (int) = %d\n", (int)sizeof (int));


What are the applications of void data types inc plus plus?

void data type is used in function declaration. It can be explained by examle void add(int,int); this will tell the compiler that no value is going to be returned by the function. int add(int,int); this indicates that an integer type value will be returned by the function


What is the maximum size of int what happes when we cross that limit?

The maximum size of INT is 1. If you go over then it will be an error.


How do you write a C program to find the total and average of three numbers in an array?

Use the following functions: int sum (const int* const a, const unsigned size) { int s = 0; for (unsigned i=0; i<size; ++i) s += a[i]; return s; } double average (const int* const a, const unsigned size) { return (double) sum (a, size) / size; } Example usage: int main () { int[3] a = {74, 42, 64}; printf ("Sum = %d\n", sum (a, 3)); // Sum = 180 printf ("Average = %d\n", average (a, 3)); // Average = 60.0 return 0; }


How do we convert between an int to a char?

With an explicit cast, for example (in Java): int i = 0; char c; c = (char) i; Please note that data may be lost in such a conversion; the explicit cast basically tells the compiler "go ahead; I know what I am doing". Without an explicit cast, the compiler won't accept the conversion.


Write a program that sort any array of integers using pointers?

#include<iostream> void insertion_sort(int* a,int len) { for(int i=1; i<len; ++i) { int* hole=a+i; int* prev=hole-1; int cur=*hole; while(hole!=a && cur<*(prev)) { *(hole)=*(prev); --hole, --prev; } *hole=cur; } } void print_array(int* a,int len) { for(int i=0; i<len; ++i) std::cout<<a[i]<<" "; std::cout<<std::endl; } int main() { int a[]={9,1,8,3,7,2,5,4,6}; int size=sizeof(a)/sizeof(a[0]); std::cout<<"Before:\t"; print_array(a,size); insertion_sort(a,size); std::cout<<"After:\t"; print_array(a,size); return(0); }


Long int size?

sizeof (long int) usually 4 or 8


Int p50 Is it a valid declaration If you declare like this what will happen?

It is an invalid declaration. If you declare like this then the compiler will terminate with a syntax error stating that there is no type 'Int' defined within this scope (all built-in types must be lowercase). Moreover, a declaration is a statement and all statements must be terminated with a semi-colon. The compiler will warn you of this as well.