answersLogoWhite

0

What is Size of int variable in c?

Updated: 8/11/2023
User Avatar

Wiki User

14y ago

Best Answer

The size of an int variable in c is a function of the compiler implementation. It is usually a word in the underlying computer architecture. Original Microsoft C/C++ compilers for the 16 bit platform defined an int as 2 bytes. Current compilers for the 32 bit platform define an int as 4 bytes. The current ANSI C standard provides that an int is at least 4 bytes, but it could be higher, say 8 bytes on a 64 bit platform.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

It depends what you mean by size. The std::string::size() member function will tell you the length of a string in chars up to but not including the null-terminator, while std::string::capacity() will tell you the maximum number of characters (excluding the null-terminator) the string will accommodate before a resize occurs. However, size could also refer to the std::string object itself, and that can be obtained via sizeof (std::string).

Or perhaps you wish to know the total memory consumed by your variable? For a string, T, of type char, the total memory consumed should be sizeof (T) + T.capacity() + sizeof (char). However, many implementations make use of the short string optimisation (SSO) to store short strings inside the object itself rather than on the free store, but this optimisation is implementation defined (it is not defined by the standard). 16 characters (including the null-terminator) is not unusual for SSO, but it's by no means universal.

If memory consumption is a concern, the most reliable method of keeping track of consumption is to implement your own string class. If you need to monitor an existing class's consumption, you'll need to override the global operator new and provide your own memory manager (not for the feint of heart).

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

One byte.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is Size of int variable in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Int a is literal in C language or not?

int a; -- variable definition"int a" -- string literal


What do you mean by initialization in c plus plus?

Not initialized variable: int myInt; Initialized variable: int myInt = 10;


What is Variable Scope?

The scope of a variable is the range, or area, in which a variable exists. // this c is global and can be referenced from anywhere int c = 1; void foo() { // this c is local to function foo and can't be referenced from the outside int c = 2; } void bar() { // if we try to reference c here, we get the value 1 from the global variable }


What is the difference between identifiers and variables in C lang?

a variable having the datattype and name, an identifier is the name of the variable for example int x; here int x; is the variable x is the identifier


How do you swap in c programming?

the simple way can be explained by example as: let there be two integers as : int a=10,b=5; if we want to use third variable then let third variable be int c; and sorting is done as : c=a; a=b; b=c; if it is to be done by without using third variable then : a=a+b; b=a-b; a=a-b; at last the variable is sorted.


What declares a variable named intNumSold?

In C, try this line: int intNumSold;


How do you declare a pointer variable in c?

int* pint; // instantiate a pointer to an int. float* pflt; // instantiate a pointer to a float.


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


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


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


Why size of integer variable changing in c and character variable size is always same.?

sizeof (int) isn't changing, only depends on the platform -- but you may use fix types like int8_t, int16_t, int32_t, int64_t from inttypes.hsizeof (char) is always 1


What is a primitive type variable in c plus plus?

same the types used in C. that is int...char...float...