Question
Coding should be in C language. Suppose we have declared the variable p in the following manner. int *p; 1. Write code to allocate memory
Coding should be in C language. Suppose we have declared the variable p in the following manner. int *p; 1. Write code to allocate memory to store 100 ints and then store the address in the variable p. 2. Briefly explain why you should always check for a NULL pointer after allocating memory. 3. Using array notation write the code that will print out every int in the block of memory we allocated in problem 1. 4. Using pointer arithmetic and the derefrence operator write the code that would increment every int by one in the block of memory we allocated in problem 1. (Note: The C operator precedence table is maybe useful here.) Suppose the following struct definition exists in your code: typedef struct someStruct{ int x; int y; double angle; }SomeStruct; Furthermore suppose the following variable has been declared, SomeStruct *sp; and that sp points to a block of dynamically allocated memory large enough to store 100 of SomeStruct. Now use pointer arithmetic and the arrow operator to print out the angle variable for each SomeStruct in this block of memory.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started