Pointer Exercise

Solve the problems once with the pointer (using variable address), and once with Dynamic Memory Allocation (DMA). Remember you must deallocate memory after working with dynamic memory allocation.

N:B: You can only declare variable to assign the address in the pointer, all value assignment, and access must be done by the pointer.

Problem Set 10.1: Pointer, Dynamic Memory Allocation

  1. Declare different types of pointer.

    • Wild Pointer

    • NULL Pointer

    • Void Pointer

    • Dangling Pointer [Only for DMA]

  2. Do Basic Pointer Operation for different primitive data types (int, float, double, char). [N.B: Make separate file for each data type]

    • Declare the Pointer. [Declare necessary variable or dynamic memory allocation]

    • Assign constant value using the pointer.

    • Print variable value and address using the variable name. [Not possible in DMA]

    • Print variable value and address using the pointer.

    • Print the address of the pointer.

  3. Take user input using different primitive data types. [You must print the address of pointer and the reference address the pointer referencing]

    1. Input an integer number using pointer and print the value using pointer.

    2. Input a float number using pointer and print the value using pointer.

    3. Input a double number using pointer and print the value using pointer.

    4. Input a character using pointer and print the value using pointer.

    5. Input a string using pointer and print the value using pointer.

  4. Solve the following problem using Pointer.

    1. Swap two numbers.

  5. Do the following different Arithmetic Operation using the Pointer.

    1. Find the Summation of two numbers.

    2. Find the Difference between two numbers.

    3. Find the Product of two numbers.

    4. Find the Quotient of two numbers.

    5. Find the Reminder of two numbers.

    6. Find the Average of three numbers.

    7. Find the Area of a Triangle using Base and Height.

    8. Find the Area of a Triangle using the length of 3 sides.

    9. Find the Area of a Circle using Radius.

    10. Convert Temperature Celsius to Fahrenheit.

    11. Convert Temperature Fahrenheit to Celsius.

  6. Do the following different Conditional Operation using the Pointer.

    1. Find Pass/Fail. [Consider 40 as lower limit of pass mark, mark range 0 to 100]

    2. Find Voter or Not Voter. [Consider 18 as lower limit of voter age, age range any whole numbers]

    3. Determining whether a number is EVEN or ODD?

    4. Find the Maximum between 2 numbers.

    5. Find the Minimum between 2 numbers.

    6. Is a number Positive/ Negative/ Zero?

    7. Find the Maximum between 3 numbers.

    8. Find the Minimum between 3 numbers.

    9. Check is a year Leap Year or Not.

    10. Find Grade of Exam.

    11. Print a digit into a word.

  7. Do the following different Loop Operation using the Pointer.

    1. Printing the following Series

      1. 1, 2, 3, 4, ⋯⋯⋯, N

      2. 1, 3, 5, 7, ⋯⋯⋯, 99

      3. 2, 4, 6, 8, ⋯⋯⋯, N

      4. 1, 1, 2, 3, 5, 8, 13, 21, 34, ⋯⋯⋯, N

    2. Calculate the Summation or Factorial of the following Series

      1. 1 + 2 + 3 + 4 + ⋯⋯ + N

      2. 1 + 3 + 5 + 7 + ⋯⋯⋯ + N

      3. 2 + 4 + 6 + 8 + ⋯⋯⋯ + N

      4. 1^2 + 3^2 + 5^2 + 7^2 + ⋯⋯⋯ + (101)^2

      5. 2^3 + 4^3 + 6^3 + 8^3 + ⋯⋯⋯ + N^3

      6. N! = 1.2.3.4. ⋯⋯⋯ .N

  8. Different Operator uses using the Pointer. [Exercise will be added later]

    • Augmented Assignment

    • Bit Wise

    • Increment, Decrement

    • Operator Precedence and Associativity

  9. Do the following Array Operation Using Pointer

    1. Input and print Array (1D, 2D) using Pointer.

    2. Copy one array to another using Pointer.

    3. Swap two arrays using Pointer.

    4. Reverse an array using Pointer.

    5. Search an element in array using Pointer.

    6. Add, Subtract, Multiply two matrix using Pointer.

    7. Find length of string using Pointer.

    8. Copy one string to another using Pointer.

    9. Concatenate two strings using Pointer.

    10. Compare two strings using Pointer.

    11. Find reverse of a string using Pointer.

    12. Sort an Array using Pointer.

    13. Return multiple value from function using Pointer.

  10. Dynamic Memory Allocation for derived data types. [Exercise will be added later]

    • Array

    • Structure, Union

Last updated