Text segment i. Initialized data segment 3. Uninitialized data segment bss 4. Heap 5. Stack A typical memory layout of a running process 1. Text Segment: A text segment, also known as a code segment or simply as text, is one of the sections of a program in an object file or in memory, which contains executable instructions.
As a memory region, a text segment may be placed below the heap or stack in order to prevent heaps and stack overflows from overwriting it. Usually, the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs, such as text editors, the C compiler, the shells, and so on. Also, the text segment is often read-only, to prevent a program from accidentally modifying its instructions. A data segment is a portion of the virtual address space of a program, which contains the global variables and static variables that are initialized by the programmer.
Note that, the data segment is not read-only, since the values of the variables can be altered at run time. This segment can be further classified into the initialized read-only area and the initialized read-write area. For instance, a variable declared static int i; would be contained in the BSS segment. By Anusua Dutta. Most often it is made as a misconception that Preprocessors or macros are part of the compilation of the program, but it is totally wrong.
Preprocessor directives are the type of macros and a phase before compilation takes place. It can be said that these are some set of instructions given to compiler to perform actual compilation. They are also known as longer construct abbreviations for macros which means the value in macros gets replaced with the segment of codes.
In this topic, we are going to learn about Preprocessor Directives in C. Whitespace is also allowed before and after the. For example, include. A macro is a code snippet that is replaced by some value of the code of macro. Any macro is mostly described and defined by its define directive. Object-like macros are the type of identifier replaced by value. It is mostly used to represent numeric constants. C has a collection of shorthand assignment operators. C offers a ternary operator which is the conditional operator?
JavaScript Tutorials jQuery Tutorials. C Operators. C Loops C while loops C do while loops C for loops. C Arrays C Strings. C Structures C Unions C typedef. Table of Contents. This is mostly the same and is not affected by the processor or the compiler used.
There is a very easy way to remember the size for int datatype. The size of int datatype is usually equal to the word length of the execution environment of the program. In simpler words, for a bit environment , int is 16 bits or 2 bytes , and for a bit environment , int is 32 bits or 4 bytes.
The float datatype is 4 bytes or 32 bits in size. It is a single-precision data type that is used to hold decimal values. It is used for storing large values. The double datatype is 8 bytes or 64 bits in size. It can store values that are double the size of what a float data type can store , hence it is called double.
In the 64 bits, 1 bit is for sign representation, 11 bits for the exponent , and the rest 52 bits are used for the mantissa.
The double data type can hold approximately 15 to 17 digits , before the decimal and after the decimal. Before moving on to the range of values for these data types, there is one more important concept to learn, which is Datatype modifiers. In the C language, there are 4 datatype modifiers , that are used along with the basic data types to categorize them further. For example, if you say, there is a playground, the other person will know that there is a playground, but you can be more specific and say, there is a Cricket playground or a Football playground, which makes it even more clear for the other person.
Similarly, there are modifiers in the C language, to make the primary data types more specific. And long and short affects the range of the values for any datatype. For example, signed int , unsigned int , short int , long int , etc. Now let's see the range for different data types formed as a result of the 5 primary data types along with the modifiers specified above.
As you can see in the table above, with different combinations of the datatype and modifiers the range of value changes. When we want to print the value for any variable with any data type, we have to use a format specifier in the printf statement.
Well, if you try to assign a value to any datatype which is more than the allowed range of value, then the C language compiler will give an error. Here is a simple code example to show this,. When a type modifier is used without any data type , then the int data type is set as the default data type.
So, unsigned means unsigned int , signed means signed int , long means long int , and short means short int. In simple words, the unsigned modifier means all positive values , while the signed modifier means both positive and negative values.
When the compiler gets a numeric value, it converts that value into a binary number, which means a combination of 0 and 1.
0コメント