Computer Science

C Memory Address

A C memory address is a unique identifier that points to a specific location in the computer's memory where data is stored. It is used to access and manipulate data stored in memory, and is an essential concept in programming languages like C that rely heavily on direct memory manipulation.

Written by Perlego with AI-assistance

3 Key excerpts on "C Memory Address"

  • Book cover image for: C++ for Financial Mathematics
    Each of these 2 32 bytes is stored in a memory location. Each possible location is itself labelled with a number. This number is called the memory address and it takes a value between 0 and 2 32 -1. Usually human beings aren’t very interested in the precise value of a memory address, so they aren’t often written down. But when one does write one out, it’s normal to write them in hexadecimal. In hexadecimal we can say that a memory location is a number between 00000000 and FFFFFFFF . This helps to clearly distinguish memory locations from “normal” numbers. A memory address is stored in C or C++ using a pointer data type. So you know what type of data is stored at that memory address, the pointer data type consists of two parts: the name of a data type that is pointed to and a * character. For example, if we write: double * dPointer = 0x00000000; then we have just declared a variable of type double* which means “a pointer to a double” or equivalently “a memory location containing a double”. We Basic Data Types and Operators 27 have specified the precise location that it points to, though it is extremely unusual to do this directly. The one place where beginners are most likely to encounter a pointer is in so-called C-strings. Look at the following code: const char * speech = To be or not to be?; This creates a variable called speech which is of type const char* . The char* means it is a pointer to a memory location containing a character. The const in front means that you can’t use the variable speech to change the text, only to read it. The memory location that speech points to contains the first letter of the speech T. The next memory location in sequence contains the letter o. The text of the speech is stored in consecutive memory locations. To mark the end of the speech, the character code 0 is used. This is illustrated in Figure 2.1. In this example, the memory location associated with the text is AB102C02 as this is where the text starts.
  • Book cover image for: Mastering C Pointers
    eBook - PDF

    Mastering C Pointers

    Tools for Programming Power

    • Robert J. Traister(Author)
    • 2014(Publication Date)
    • Academic Press
      (Publisher)
    In 8-bit terms, we can break the 32-bit address down into a segment and an offset as in: SEG OFFSET Ox bOOO 0000 If you are accustomed to providing addresses in 8-bit values, and most users of MS-DOS machines and software are, then simply follow the hexadecimal value with four zeros. Mathematically, the conversion method involves multiplying the 8-bit address by 0x1 0000. If you prefer to work within the decimal system (cum-bersome when dealing with memory addresses), then multiply the decimal memory address by 65536 decimal. In any event, the previous program must use absolute address-ing when dealing with memory locations, and each address is given as a 32-bit (4-byte) quantity. OxbOOOOOOOis the address of the start of the monochrome display buffer. The assignment line uses a cast operator to coerce the numeric value to type c h a r *. This is necessary in type-casting the numeric value to a form that is acceptable to the pointer. Once the assignment of a memory address has been made, we know that a points to the start of, in this case, the monochrome screen buffer. This means that *a will access the object value stored in the byte at this location. Therefore, a construct of: *a = 6 7 ; reassigns a value of 67 to this byte. The letter ' C ', which is repre-sented by decimal 67, appears in the upper left corner of the screen. This is far more efficient from both a programming and an execution speed standpoint when compared to calling the pokeb() 84 Chapter 6 function. Calling a function from a program requires additional execution time and larger code size. When a C program calls a function, the calling program actually relinquishes control to the function. This takes more time than if the function were actually written within the calling program, proper. You can literally see the difference calling a function like pokeb() makes in execution speed.
  • Book cover image for: Computer Systems Architecture
    222 ◾ Computer Systems Architecture starts execution, the operating system loads the base register, and each memory access is calculated by adding the content of the register to the displacement defined in the instruc-tion. In this way, it is possible to access a very large address space and to maintain control of the instruction sizes. Calculating the real address is done by the MMU for each memory access, and it includes a simple addition of the logical address that appears in the instruction and the base register ( Figure 5.30 ). The principle that led to this addressing mode is locality of reference, which is also responsible for the hierarchical memory architecture already discussed. This locality of reference, which will be further elaborated on in Chapter 6 , “Cache Memory,” means that when a program is executed, most of the time it will use items of data that are close to each other and the instructions for which are in close proximity. For example, when entering a method or a function, all the executed instructions belong to the same method so they reside very close to each other. The same happens when the program is working on a data record or is analyzing an array. The data items to be addressed belong to the same record or array and thus are relatively close. The PC convention for these memory chunks is a segment, and in general, there are three types of segments with a base register for each one: • Code segment , used for the program’s instructions. The register that holds the code base address is CS (code segment). To reinforce the system’s data integrity, the con-tent of the code segment cannot be accessed (read or written) by other processes, and only the operating system and the MMU can access its content. • Data segment , used for storing the program’s data. The register that holds the data-base address is the DS (data segment). Due to the need of some programs to use very large data address spaces, sometimes the program may have two data segments.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.