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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!