answersLogoWhite

0


Best Answer

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

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Get size of int using sizeoff?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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); }


Long int size?

sizeof (long int) usually 4 or 8


Write a program in C which has an integer array and its size as parameter and returns the sum of the values of the elements of the elements of the array Write a main function and show its usage?

#include using std::cin;using std::cout;using std::endl;int main(){int sizeOfArray = 5;int myArray[] = {0};cout myArray[i];}int sum = 0;for (int j = 0; j < sizeOfArray; j++){sum += myArray[j];}cout


1 write a c function that takes a parameters two integer arrays and their sizeboth arrays are of the same size and returns a 1true if the arrays have the same contents or a 0 false if not?

int comp(const int a1[], const int a2[], const int size) { int i; for(i = 0; i &lt; size; ++i) { if(a1[i] != a2[i]) { return 0; } } return 1; }


How do you write a program in c plus plus that reads two integer arrays each having 10 elements and then prints the sum of the products?

#include&lt;iostream&gt; #include&lt;iomanip&gt; #include&lt;time.h&gt; void print(int a[], size_t size) { using std::cout; using std::endl; using std::setw; for(size_t index=0; index&lt;size; ++index) cout&lt;&lt;setw(5)&lt;&lt;a[index]; cout&lt;&lt;endl; } int main() { srand((unsigned)time(NULL)); const size_t size=10; int a[size], b[size], c[size]; // Initialise a and b with random integers (range 1-99) for(size_t index=0; index&lt;size; ++index) { a[index]=rand()%99+1; b[index]=rand()%99+1; } // Initialise c with products of a and b. for(size_t index=0; index&lt;size; ++index) c[index]=a[index]*b[index]; // Calculate sum of c. int sum=0; for(size_t index=0; index&lt;size; ++index) sum+=c[index]; // Print results. std::cout&lt;&lt;"Array a:\t"; print(a,size); std::cout&lt;&lt;"Array b:\t"; print(b,size); std::cout&lt;&lt;"Products:\t"; print(c,size); std::cout&lt;&lt;"Sum product:\t"&lt;&lt;sum&lt;&lt;std::endl; }

Related questions

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

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


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

#include&lt;iostream&gt; #include&lt;time.h&gt; #include&lt;iomanip&gt; #include&lt;string&gt; void swap(int&amp; x, int&amp; y) { x^=y^=x^=y; } void bubble_sort(int* A, int size) { while(size) { int n=0; for(int i=1; i&lt;size; ++i) { if(A[i-1]&gt;A[i]) { swap(A[i-1], A[i]); n=i; } } size=n; } } void insertion_sort(int* A, int size) { for(int i=1; i&lt;size; ++i) { int value=A[i]; int hole=i; while( hole &amp;&amp; value&lt;A[hole-1] ) { A[hole]=A[hole-1]; --hole; } A[hole]=value; } } void selection_sort(int* A, int size) { for(int i=0; i&lt;size-1; ++i) { int j=i; for(int k=i+1; k&lt;size; ++k) if(A[k]&lt;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&lt;&lt;prompt&lt;&lt;"\t"; for(int i=0; i&lt;size; ++i) std::cout&lt;&lt;std::setw(2)&lt;&lt;A[i]&lt;&lt;" "; std::cout&lt;&lt;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&lt;&lt;prompt&lt;&lt;": "; std::cin&gt;&gt;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&lt;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&lt;&lt;"You chose "; switch(choice) { case(0): std::cout&lt;&lt;"bubble"; break; case(1): std::cout&lt;&lt;"insertion"; break; case(2): std::cout&lt;&lt;"selection"; break; } std::cout&lt;&lt;" sort...\n"&lt;&lt;std::endl; print_array( A, size, "Before sorting" ); sort(A, size, choice); print_array( A, size, "After sorting" ); delete [] A; } return(0); }


Write a program to display biggest integer in a one Dimensional array using pointer?

#include&lt;iostream&gt; int max(int* a, size_t size) { size_t max=a[0]; for(size_t index=0; index&lt;size; ++index) if( max&lt;a[index] ) max=a[index]; return( max ) } int main() { int a[5]={1,5,8,7,4}; int m=max(a,5); // invariant: m==8 }


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 delete an element from an array?

C++ code example using a vector object (dynamic array): #include&lt;iostream&gt; #include&lt;vector&gt; using namespace std; typedef std::vector&lt;int&gt; vec; typedef std::vector&lt;int&gt;::iterator it; void init_array(vec&amp; v) { v.clear(); for(int i=1; i&lt;=10; ++i) v.push_back(i); } void print_array(vec&amp; v) { for(it i=v.begin(); i!=v.end(); ++i) cout&lt;&lt;*i&lt;&lt;" "; cout&lt;&lt;endl; } it get_element(vec&amp; v, unsigned int index) { it i=v.begin(); while(index--) ++i; return(i); } int main() { vec v; init_array(v); cout&lt;&lt;"Initial array:\t"; print_array(v); // Remove element at index 3 (the 4th element). v.erase( get_element(v, 3)); cout&lt;&lt;"Modified array:\t"; print_array(v); return(0); } Since Java is object-oriented, you can use a similar approach to the above. However, with C, there's a bit more work involved in managing the memory allocation, however the overall approach is the same: #include&lt;iostream&gt; using namespace std; int* init_array(unsigned int len) { int* p=(int*)malloc(len*sizeof(int)); for(unsigned int i=0; i&lt;len; ++i) p[i]=i+1; return(p); } void print_array(int* p, unsigned int len) { for(unsigned int i=0; i&lt;len; ++i) cout&lt;&lt;p[i]&lt;&lt;" "; cout&lt;&lt;endl; } int main() { unsigned int size; int* p; size=10; p=init_array(size); cout&lt;&lt;"Initial array:\t"; print_array(p,size); // Remove element at index 3 (the 4th element) --size; for( unsigned int y=3; y&lt;size; ++y) p[y]=p[y+1]; p=(int*)realloc(p,size*sizeof(int)); cout&lt;&lt;"Modified array:\t"; print_array(p,size); delete [] p; return(0); }


Long int size?

sizeof (long int) usually 4 or 8


What is the size of an identifier declared as integer in C?

int myvar; printf ("size of myvar is %d\n", (int)sizeof (myvar));


In c language size of data type int?

printf ("sizeof (int) is %d bytes", (int)sizeof (int)); Most likely it will be 2 or 4.


Write a program in C which has an integer array and its size as parameter and returns the sum of the values of the elements of the elements of the array Write a main function and show its usage?

#include using std::cin;using std::cout;using std::endl;int main(){int sizeOfArray = 5;int myArray[] = {0};cout myArray[i];}int sum = 0;for (int j = 0; j < sizeOfArray; j++){sum += myArray[j];}cout


1 write a c function that takes a parameters two integer arrays and their sizeboth arrays are of the same size and returns a 1true if the arrays have the same contents or a 0 false if not?

int comp(const int a1[], const int a2[], const int size) { int i; for(i = 0; i &lt; size; ++i) { if(a1[i] != a2[i]) { return 0; } } return 1; }


What is a implementation on n numbers of term in bubble sorting?

void bubblesort (int* array, int size) { if (!array size&lt;2) return; int last_swap = size; while (last_swap&gt;0) { int n=last_swap; for (int i=1; i&lt;last_swap; ++i) { if (array[i]&lt;array[i-1]) { array[i]^=array[i-1]^=array[i]^=array[i-1]; n=i; } last_swap = n; } }


How do you write a program in c to swap two values by using functions?

#include using namespace std; void swap(int &amp;a, int &amp;b); int main() { int x=5,y=3; cout