Pointers and Memory Allocation in C

Verified

Added on  2020/02/18

|2
|448
|58
AI Summary
This C programming assignment delves into the concepts of pointers, memory allocation, and linked lists. It covers topics such as variable declaration using pointers, accessing values through pointers, arithmetic operations involving pointers, memory allocation functions like malloc and calloc, and the structure of a linked list. The assignment also includes examples demonstrating pointer usage in various contexts.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
1. a) mp has its own allocated memory space independent of m and n.
c) The program should display m=2 n=3 *mp = 2 *np = 3
d) mp points to m
e) np points to n
2. e) in line 07 – the programmer can write an arithmetic operation which contains the
variable.
3. a) in line 07 – the programmer can write an arithmetic operation which contains the
variable.
b) in line 03 – the programmer can write a logical expression for the if – statement,
which contains the variable.
c) in line 11 – the programmer can write an arithmetic operation which contains the
variable.
d) in line 13 – the programmer can write an arithmetic operation which contains the
variable.
4. a) To get to a specific node in a linked list, the program needs to travel through the list
sequentially.
d) Fundamental data type used to build a linked list is a pointer to a structure, which
contains at least one pointer to another structure of the same type.
5. b) printf("%d \n", *(xp+1)); and printf("%d \n", xp[1); would print the same value
c) printf("%d \n", *xp)); would print 10 as the output.
d) printf("%d \n", *(xp+1)); would print 5 as the output.
6. a) A function can have any number of inputs, however a function can output only one
value through return keyword.
b) The key functions that allow dynamic memory allocation/deallocation through
pointers is provided by stdlib.h
d) An integer is a variable that contains a whole number.
e) consider an array defined as int arr[10]; The variable arr is in fact a pointer.
7. d) The malloc, calloc, realloc functions allocate memory to a pointer that is not
necessarily contiguous.
8. e) fun(&d, d);
9. a) a variable that stores an integer
b) the memory location of the variable.
d) a variable that stores the memory location of an integer.
e) the integer value stored in the memory location
c) the memory location of the beginning of the array.
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
10. c) if the value of x is printed after line 05, before line 06, it would be 1.
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]