Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

.. Pertaining to C language: 1. True or False. If ptrv = &v then *ptrv is the eq

ID: 3838643 • Letter: #

Question

..

Pertaining to C language:

1. True or False. If ptrv = &v then *ptrv is the equivalent to v

2. True or False. If ptrw = &w and ptrv = ptrw then *ptrv can set the value of w.

3. True or False. Indirection pointers differ from dereferenced pointers.

4. True or False. Given that ptrv is declared as a integer pointer printf ("%d", ptrv ) is the proper way to print

5. True or False. An Array name works as a pointer constant

6. True or False. A character pointer worksa the same as a double pointer except it points at different data type

7. True or False. malloc finds and reports non allocated contiguous memory in the heap to meet specifications

8. True or False. calloc acts as a void pointer

9. True or False. malloc does not return a value if there is not enough nonallocatted memory to meet the specification

10. True or False. No typecasting is used in memory allocation

Explanation / Answer

1. It is a true statement because ptrv contains tha address of variable v in which some value is stored. Therfore, *ptrv can access and modify the value of the variable v.

2. It is a true statement, because ptrw contains the address of the variable w in which some value is stored and ptrv contains the address stored in ptrw variable as both of them are of pointer data type, so setting the value of *ptrv will also change the value of the variable w.

3. It is a false statement because both refers to the same concepts as indirection pointers or dereferenced pointers, we can indirectly access the value of the variable by accessing its location in the memory, which holds the address of that variable, holding a particular variable and this operation is accompolished using (*) operator.

Ex - int w = 56;

int *ptrw = &w;

printf("%d",*ptrw);

Here, we are indirectly accessing the value of the variable w by accessing the value of the pointer variable ptrw, which holds the address of the variable w, containing a numerical value 100. So, using (*) unary operator with ptrw variable, will indirectly access the value of the variable w which is known as dereferencing pointer or indirection pointer.

4. It is a true statement, because printf("%d",ptrv) will print the address of the variable holding a particular numerical variable. Thereofre, it will not create any compilation or runtime error.

5. It is a true statement because an array name is equivalent to a pointer constant because it always points to the location of the value at the first index which can't be changed.

Ex- int &a[10];

Here, in this example, there is no difference between the statements a and &a[0] as both of them points to the location of the first index of the array, which can't be changed.

6. It is a true statement because both works in the same manner except that both of them refers to the different data types.

Ex - char demo_charvar = 'C';

char *ptr_char = demo_charvar

double demo_dblvar = 345.90;

double *ptr_dbl = demo_dblvar;

7. It is a false statement as malloc allocates contiguous blocks of memory in the heap at runtime for allocating the memory to the variables and methods for the faster execution of the program.

8. It is a true statement because calloc allocates the space in the memory for an array of elements, initialises all of the elements in the array to zero and then it returns a void type pointer to the memory. Therfore, calloc acts as a void pointer.

9. It is a true statement because malloc allocates the non allocated memory in the heap to any type of pointer using typecasting. But, if it fails to allocate the enough non allocated space in the memory, then it returns the NULL pointer or in other words, it does not return the value.

10. It is a true statement because both malloc() and calloc() function returns the void type pointer which can be assinged to any type of pointer without explicit typecasting. In other words, it means that it is being implicitly typecasted by the compiler itself or implicity done by the compiler itlsef, which will not run the program into compilation or rin time error. So, compiler implicitly typecasts the void type pointer to any pointer type. Therefore, typecasting is used in memory allocation.