answersLogoWhite

0


Best Answer

int * gred ;

gred = new int [100] ; // this example snippet creates 100 ints

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a C plus plus statement to allocate memory cells dynamically and store the memory address in a pointer to an integer named gred?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the process of allocation of memory for an integer type variable?

To dynamically allocate memory, use the following function (stdlib.h I believe): int *variable1 = malloc(sizeof(int));


Explain pointer with the help of an example?

Pointers are data types that hold integer values, those "integer" values are simply addresses of another variables.Example:int x = 15; // this is an integer variable with value 15int* ptr; // this is a pointer to an integerptr = &x; // now we assigned the address of x to the pointer ptr// if you want to access the value of x (15 in this example),// you should use the deterrence *// so you can say:printf("%d", *ptr); // this will print 15// you can print the value of ptr (which is the address of x) using:printf("%p", ptr); // this will print an integer, which is the address of x.==========================================================More explanation, let's imagine that this is a memory:-00--01-02-03-04 =====> these are the address of the memory|--- |--- |---|---|---| =====> values inside the memoryFor the example I gave before, let's imagine the following:-00-01-02--03--04|---|15|--- | 01 |---|------x------- ptrAs you can see, x hold the value 15, ptr holds the value 01 which is actually the address of x. Now ptr have a distinct address too, which is 03.In reality, the address of a memory is longer, and usually represented as hexadecimal values. example 0x002154You can find more information here:http://en.wikipedia.org/wiki/Pointers


What is the purpose of the dereference operator when used with a pointer variable?

Data type is mandatory in every variable-declaration.Example:int i; -- integerint *pi; -- integer-pointerint ai[10]; -- integer-arrayint *api[10]; -- array of integer-pointersint (*api)[10]; -- pointer to integer-array


Are pointers integers?

A pointer holds a memory address, from 0 to the upper limit of your memory (in 32 bit addressing this is up to 2^32, 64 bit is up to 2^64 bytes). So in math terms, a pointer could be considered a non-negative integer. However this is not the same as the integer type used in C and other languages, which refers to how the data at that memory address (the raw bits) is interpreted by the system. So the expression "int *x;" declares a pointer to an integer, but x is a memory address, not a literal C-style integer. The value pointed to by x, however, will be interpreted as a literal C-style integer. It may be easier to see using a pointer to a char: char character = 'C'; char *pointerToCharacter = character; In this case, character is a standard char variable, and pointerToCharacter is a pointer (which is a memory address) that points to the location in memory of a character.


What is the use of Default statement in switch case?

C++ Provides a multiple branch selection called as switch. This selection statement succesively test against a list of integer or character constants. When a match is found the statements associate with constants are executed. When no match is found default statement is used.

Related questions

What is the process of allocation of memory for an integer type variable?

To dynamically allocate memory, use the following function (stdlib.h I believe): int *variable1 = malloc(sizeof(int));


Which statement is true the square root of an integer will always be an integer or the square of an integer will always be an integer?

the square of an integer will always be an integer


Do Prove that the product of an integer and arbitrary integer is even?

The statement is not true. Disprove by counter-example: 3 is an integer and 5 is an integer, their product is 15 which is odd.


What statement is true if P is an Integer and Q is a nonzero integer?

Any fraction p/q where p is an integer and q is a non-zero integer is rational.


What is the integer of A gain of 5 yards on the first down write integer that is represented in statement?

5


When comparing two integers the integer with the bigger absolute value is always the greater integer?

The statement is false.


Given two is an even integer or three is an even integer Determine the truth value of this disjunction Justify your answer?

True. The first statement is true and the second statement is false. In a disjunction, if either statement is true, the disjunction is true.


Find 3 consecutive even integers if the product of the first integer and two two less than the second integer is four more than five times the third integer and what is the let statement?

The let statement is: let the smallest of the three integers be x.


What does writing an integer greater than itself mean?

It is an invalid statement.


What is an arbitrary positive integer?

"Arbitrary" simply means any. So this refers to any positive integer. It may be used to make a statement that is true for every positive integer.


What stament is always trueabout the sum of a negtive integer and positive integer?

The statement is: "Their sum is always an integer." Whether the sum is negative or positive depends on the two original integers.


When you subtract a positive integer from a positive integer do you get a positive integer?

Not necessarily, for example: If you subtract 3 from 4, then you get +1. But if you subtract 4 from 3, you get -1. The answer will always be an integer, but you cannot make a general statement about the sign, without knowing more information.