answersLogoWhite

0


Best Answer

Yes, but you may cause truncation error because the short variable does not necessarily have the same range as an int variable. Most modern compilers will flag this as a warning. If you know that the value of the int variable will not exceed the range of a short variable, you can explicitly prevent the warning with a typecast, i.e. someShort = (short) someInt; and the compiler will assume that you know what you are doing.

User Avatar

Wiki User

βˆ™ 13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

βˆ™ 14y ago

Yes, because the int is 32 bit and a short is 16 bit.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can an short value be assigned to int variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


How do you give values to variable?

it depend on the programming language u use. for instance in c, just decalre the variable and equal it to the value it is to take. eg. my_age=21; /*my_age is the decared variable and 21 is the assigned value*/ //for php $my_age=21; /*my_age is the decared variable and 21 is the assigned value*/ for strings (in php)eg. $my_age="none of ur business" /*$my_age is the variable and the string "none of ur business" is the assigned value*/


Can an float value be assigned to int variable?

Yes, an integer can be assigned as a float value.But it get stored as a float value, that is an implicit type conversion occurs during compilation.Smaller data types are convertible to larger data types.eg:float b=12;// an integer constant is assigned to a float variableprintf("%f",b);// when printing b it will print as 12.000000


How do you create an static int as an instance variable?

You create a static integer as an instance variable by declaring it in a class using a statement that consists of the privacy level, then the keywords "static" and "int", and finally, the name of the variable. For example:public class TheAnswerIsHere {public static int example = 0;}will define an int example with initial value 0. The variable is accessed through the statement TheAnswerIsHere.example.


What is pointer initialization?

Assigning an initial value to a pointer variable. Example: int *p= NULL;

Related questions

What is the difference between data and variable?

data type refers to the kind of value that is held by a particular variable. For ex: an int variable contains integer value, a string holds a alpha numeric value etc. variable refers to the name of a value using which we can refer to this value. Ex: public int age = 28; here int is the data type and age is the variable.


What is the types of data?

int, but can be assigned to a short, long or char as well


Complex assignment in java?

The team at New Assignment Help Australia truly exceeded my expectations! I used their Coding Assignment Help for a challenging web development task, and the results were impressive. They delivered a project that was both technically sound and visually appealing. What sets them apart is their attention to detail and commitment to quality. The entire process was stress-free, and the final product helped me secure top grades. If you’re looking for a trusted service for your assignments, I wholeheartedly recommend them


What is difference between equals and equals equals operators?

The equals operator is used for assigning a value to a variable. ex String name = "efu"; the equals equals operator is used for comparaing if the given value is equal to another value which is assigned for a variable. ex int i = 0; int j = 5; if( i == 0){ System.out.println(j+"can't be divided by"+i); }else{ System.out.println("answer is " +j/i); }


Store value in variable c plus plus?

#include<iostream> int main() { int var=42; // store the value 42 in a variable named var. return(0); }


What is the data type of 5?

int, but can be assigned to a short, long or char as well


What is the main variable?

Variables are names for which the value may be altered. That is, the value of a name is variable. For example: int x; // Declares a variable named x. int y = 0; // Declares and initialises a variable named y. x = 5; // Changes the value of the variable named x. y = x; // Changes the value of the variable named y. By contrast, constants are names for which the value does not change: const int z = 10; // Declares a constant named z, which will always have the value 10.


What defines a data type?

the type of data which we store in a variable.. example: int a=10; /*here a is variable (data) which is of type int and stores a value 10.*/


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.


How do you give values to variable?

it depend on the programming language u use. for instance in c, just decalre the variable and equal it to the value it is to take. eg. my_age=21; /*my_age is the decared variable and 21 is the assigned value*/ //for php $my_age=21; /*my_age is the decared variable and 21 is the assigned value*/ for strings (in php)eg. $my_age="none of ur business" /*$my_age is the variable and the string "none of ur business" is the assigned value*/


Can an float value be assigned to int variable?

Yes, an integer can be assigned as a float value.But it get stored as a float value, that is an implicit type conversion occurs during compilation.Smaller data types are convertible to larger data types.eg:float b=12;// an integer constant is assigned to a float variableprintf("%f",b);// when printing b it will print as 12.000000


What are variables in C?

variable is must start with letter or ( _ ) under score ex : int a; means a is a variable we can store value on it