Skip to main content

Memory, Memory Address in Programming Language




A computer provides a Random Access Memory (RAM) for storing executable program code as well as the data the program manipulates. This memory can be thought of as a contiguous sequence of bits, each of which is capable of storing a binary digit (0 or 1). Typically, the memory is also divided into groups of 8 consecutive bits (called bytes). The bytes are sequentially addressed. Therefore each byte can be uniquely identified by its address.


Figure: Bits and bytes in memory.


The C++ compiler generates executable code which maps data entities to memory locations. For example, the variable definition

int salary = 65000;
causes the compiler to allocate a few bytes to represent salary. The exact number of bytes allocated and the method used for the binary representation of the integer depends on the specific C++ implementation, but let us say two bytes encoded as a 2’s complement integer. The compiler uses the address of the first byte at which salary is allocated to refer to it. The above assignment causes the value 65000 to be stored as a 2’s complement integer in the two bytes allocated.



Figure:  Representation of an integer in memory.


While the exact binary representation of a data item is rarely of interest to a programmer, the general organization of memory and use of addresses for referring to data items (as we will see later) is very important.

Comments

Popular posts from this blog

Object-Oriented Programming and JAVA Programming Language

  Object-Oriented Programming and:   Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, messaging, modularity, olymorphism, and inheritance. Many modern programming languages now support OOP, at least as an option. JAVA Programming Language: Object-oriented programming is at the core of Java. In fact, all Java programs are object-oriented, this isn’t an option the way that it is in C++, for example. OOP is so integral to Java that you must understand its basic principles before you can write even simple Java programs. Therefore, this chapter begins with a discussion of the theoretical aspects of OOP.

Read or input form user in Java using BufferedReader

 BufferedReader use to read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.The buffer size may be specified, or the default size may be used. The default is large enough for most purposes. In Java  BufferedReader is a efficient method to read an input. Here given a short example to read a string from user and print it: package palindrome; import java.io.BufferedReader; import java.io.InputStreamReader; public class  inputExample   {     public static void main(String[] args) throws Exception {    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     String s = new String();       s =br.readLine();     System.out.println(s);     } }

Absolute value and Floating-point absolute value function in C Programming Language

Absolute value function in C Programming Language is abs(i), Its return the absolute valu of i. where  i  is any positive or negative  number. It is integer type function. The include file of abs(i) is stslib.h Observe under program: #include<stdio.h> #include<stdlib.h> int main(void) { int a; scanf("%d",&a); printf("%d",abs(a)); } Here I use a integer number. Input it by scanf and print the Absolute value by abs() function. Floating-point Absolute value function in C Programming Language is fabs(i), Its return the absolute valu of i. where  i  is any positive or negative  Floating-point number. It is double integer type function. The include file of fabs(i) is math.h Observe under program: #include<stdio.h> #include<stdlib.h>  int main(void) { float a; scanf("%f",&a); printf("%.2f",fabs(a)); } Here I use a integer number. Input it by scanf and print the Floating-point Absolute value b