C pointers example programs

By IncludeHelp Last updated : March 10, 2024

What are C pointers?

Pointers are the main and very useful feature of C programming. Pointers are special kind of variable by its amazing features; these are the variables that can store address of another variable.

Pointers can stores address of another variables, can access value of that variable (which address is stored in the pointer variable), can assign value to that variable too.

Features of C pointers

Here are some features of pointers:

  • By using pointers we can get multiple values from the function, as we know a function can return only one value but by passing arguments as pointers we can get more than one values from the pointer.
  • By using pointers dynamic memory can be created according to the program use. We can save memory from static (compile time) declarations.
  • By using pointers we can design and develop complex data structures like STACK, QUEUE, LINKED LIST etc.
  • Amazing feature of pointes: Pointers provide direct memory access.

Disadvantages of the pointers

Since pointers has many features but there are some disadvantages of pointers

  • Failed to protect memory addresses (locations) - Since pointer can access direct memory so memory cannot be protected.
  • Uninitialized pointers can cause of segmentation fault.
  • Pointers variables are slower than normal variables.
  • Pointers always required Free Memory for Dynamically Allocated Memory.

C Pointers Programs (Examples)

Here are the lists of some solved c programming pointers solved programs/examples for your practice, all programs have source code with output and explanation. This section contains solved programs on pointers, pointers with simple variable, pointers with conditional and control statements, array and pointers, pointers with strings, structure and unions.

List of C pointers Programs

  1. Program to create, initialize, assign and access a pointer variable.
  2. Program to swap two numbers using pointers.
  3. Program to change the value of constant integer using pointers.
  4. Program to print a string using pointer.
  5. Program to count vowels and consonants in a string using pointer.
  6. Program to read array elements and print with addresses.
  7. Program to read and print student details using structure pointer, demonstrate example of structure with pointer.
  8. Program to print size of different types of pointer variables.
  9. Program to demonstrate example of double pointer (pointer to pointer).
  10. Program to demonstrate example of array of pointers.
  11. An Example of Null pointer in C
  12. Making a valid pointer as NULL pointer in C
  13. Modify value stored in other variable using pointer in C



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.