answersLogoWhite

0

How you assign int to short if s is short and i is int?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

By type casting since int is of larger bits than short

s=(int)i;

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How you assign int to short if s is short and i is int?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why does int has the same range as short?

The int is a data type in c, c++ or java, It can divided in to two parts that is short and long. Int short if of same size as int (2).


What if -1 is assigned to a unsigned variable in C plus plus?

If you assign -1 to a unsigned variable it will contain the biggest number its able to hold. For example if you assign -1 to a unsigned int it will be 4294967295 as its the biggest number a unsigned int can hold.


What does USP Priority Int mean?

Int is short for international.


What are the four integral types in C plus plus?

There are far more than 4 integral types in C++. As of C++11, there were 27 integral types: bool char signed char unsigned char wchar_t char16_t char32_t short signed short unsigned short short int signed short int unsigned short int int signed int unsigned int long signed long unsigned long long int signed long int unsigned long int long long signed long long unsigned long long long long int signed long long int unsigned long long int


Is int a statistical function?

No, 'int' is short for 'integer' (or 'integral' etc).


How do you assign the value 45 to the variable PassMark using High-level programming language?

In C: int pass_mark; pass_mark = 45; In C++: int pass_mark {45};


How do you write a program that generates three random numbers and prints the largest?

For this you need two variables, a and b. Generate the first number and assign it to a. Generate the second and assign it to b. If b is greater than a, assign b to a. Generate the third number and assign it to b. If b is greater than a, assign b to a. Print a. A better method is to use the following function to determine the largest of any two values: int max (int x, int y) { return x>y ? x : y; } Once you know the largest of any two values you can easily determine the largest of any three values with a nested call: int max_of_three (int a, int b, int c) { return max (max (a, b), c)); } Note that we determine the largest of a and b first and then pass that value to a second call along with c, thus establishing the largest of all three. To determine the largest of n values, store the numbers in an array and pass the array and its length to this function: int max_of_n (int a[], size_t n) { int m = a[0]; // store first value while (--n) if (a[n]>m) m=a[n]; // update m whenever a[n] is greater return m; }


Write a program in c plus plus that will convert an integer pointer into an integer and viceversa?

You cannot physically convert variables of one type to another type, you can only cast them to create a new type (a new variable), providing the new type is covariant with the existing type. int i = 100; // int variable int* p = &i; // pointer to int The indirect value of p is i (100) while the direct value of p is the address of i. And because p is a variable, it has an address of its own. Thus converting the pointer p to an int can be done in one of three ways: int j = *p; // assign indirect value of p to j (thus j==100). int k = (int) p; // cast the address stored in p and assign to k (k==address of i) int l = (int) &p; // cast the address of p and assign to l (l==address of p)


What is memory variable. how can you create array memory variable?

You probably mean pointer variable rather than memory variable. You create an array of pointer variables just as you would an array of any other type: #include<stdio.h> #include<malloc.h> // Fixed-length arrays: void foo1 (void) { const unsigned n = 10; unsigned i; // an array of n int types int a[n]; // an array of n pointer-to-int types int* b[n]; // assign the address of each indexed element in a[] to the corresponding pointer element in b[] for (i=0; i<n; ++i) b[i] = &a[i]; // assign values to integers in a[] via pointers in b[] for (i=0; i<n; ++i) *b[i] = i * 10; // print the values in a[] printf ("a[] = {"); for (i=0; i<n; ++i) printf("%d%s", a[i], i<n-1?", ":""); printf ("}\n"); // print the values pointed to by b[] printf ("b[] = {"); for (i=0; i<n; ++i) printf("%d%s", *b[i], i<n-1?", ":""); printf ("}\n"); } // Variable-length arrays: void foo2 (unsigned n) { unsigned i; // an array of n int types int* a = (int*) malloc (n * sizeof (int)); // an array of n pointer-to-int types int** b = (int**) malloc (n * sizeof (int*)); // assign the address of each indexed element in a[] to the corresponding pointer element in b[] for (i=0; i<n; ++i) b[i] = &a[i]; // assign values to integers in a[] via pointers in b[] for (i=0; i<n; ++i) *b[i] = i * 10; // print the values in a[] printf ("a[] = {"); for (i=0; i<n; ++i) printf("%d%s", a[i], i<n-1?", ":""); printf ("}\n"); // print the values pointed to by b[] printf ("b[] = {"); for (i=0; i<n; ++i) printf("%d%s", *b[i], i<n-1?", ":""); printf ("}\n"); // release allocated resources free (b); free (a); } int main () { foo1 (); foo2 (10); return 0; }


In unix Which command do you use to assign a socket to a specific address?

There isn't a generalized way from the command line in Unix to connect to a socket; there are socket libraries you can utilize from within the 'C' language to assign, bind, and connect to a specific socket address. For example: int connect(int s, const struct sockaddr *name, int namelen); In Linux, you can use the 'socket' command to connect to a specific socket as: socket ?options? host port Where the host is the IP address and the port is the port number (giving you the socket address).


What is int social studies?

Int social studies is short for international social studies.


How do you write a c program that sums a sequence of integers?

The simplest way is to store the sequence in an array, then pass the array to the following function: int sum (int* a, int size) { int s = 0; for (int i=0; i<size; ++i) s += a[i]; return s; } Example usage: int x[5] = {1, 2, 3, 4, 5}; int s = sum (x, 5); assert (s == 15);