Domanda |
Risposta |
What are the 2 things data types all have? inizia ad imparare
|
|
[1] a set of allowable values; [2] a set of operations on these values.
|
|
|
what are the typical Elementary Data Types inizia ad imparare
|
|
[1] numeric (integer and floating point), [2] boolean, [3] character, [4] enumerated, and [5] reference or pointer.
|
|
|
what are Enumerated Types inizia ad imparare
|
|
[1] Enumerated types are ordinal type that the possible values can be associated with the set of positive integers (In Java, the primitive ordinal types are integer and char). [2] Enumerated types can be user-defined elementary types
|
|
|
inizia ad imparare
|
|
[1] Pointer, or reference, variables have a memory address as their value—we say they “point” to another data item. [2] Pointers are useful in providing a way to manage (allocate and de-allocate) dynamic storage - heap memory.
|
|
|
how is a pointer type declared? inizia ad imparare
|
|
The declaration: precede a variable name by a “*”: eg int number, *numPtr;
|
|
|
describe the following code " int number, *numPtr; " inizia ad imparare
|
|
This means, at runtime: [1] number is associated with a location in memory at which an integer is stored. [2][numPtr is associated with a location in memory at which a memory address is stored.
|
|
|
describe the use of & with pointers inizia ad imparare
|
|
The & operator gives the address of a variable; after executing: number = 42; numPtr = &number; the value of numPtr is the address of variable number.
|
|
|
what is Pointer Dereferencing inizia ad imparare
|
|
We use the pointer dereferencing operator * to access the value pointed to by a vriable
|
|
|
explain the following code "[1] number = 42; numPtr = &number; [2] printf("%d\n", *numPtr);" inizia ad imparare
|
|
We use the pointer dereferencing operator * to access the value pointed to by numPtr: printf("%d\n", *numPtr); which here will display 42.
|
|
|
inizia ad imparare
|
|
A special value null (null is actually stored as a 0) is assigned to any pointer variable to signify that it doesn’t point to any location.
|
|
|
explain the following code " int *p; int *q int a = 100; p=&a; *q = *p; q = p; " inizia ad imparare
|
|
*q = *p; This copies the contents (100) of the memory location pointed by p to q. whereas q = p; copies the value (a memory address) of p to q.
|
|
|
inizia ad imparare
|
|
calloc allocates a block of memory of "n elements" of "size" bytes each and initializes contents of memory to zeroes. It contain info for memory organisation.
|
|
|
inizia ad imparare
|
|
malloc allocate specified size (no organisation info) of memory but does not erase them, therefore the memory may contain garbage values.
|
|
|
what are Dangling Pointers inizia ad imparare
|
|
pointers that do not point to a memory location due to deallocation
|
|
|