C Programming language

C Standard Library Function

Day 1: Introduction and brief history of C Programming language

Day 1: Advantages and Disadvantages of C, C Keywords, Data type modifiers in C

Day 1: Data types in C Programming language

Day 1: Secondary data types, Primitive and Non-primitive data types

Day 1: C Variables, C Constant, Format Specifiers in C

Day 2: Write first C program

Day 2: Flow of C program with example, main(), printf(), scanf()

Day 2: Operaters in C Programming language, Arithmetic operators

Day 2: Relational operators and Logical Operators in C Programming language

Day 2: Assignment, Increments and Decrement Operators in C Programming language

Day 3: Conditional statement: if else statement in C Programming language

Day 3: Conditional statement: switch statement in C Programming language

Day 3: Jump statements: return statement in C Programming language

Day 3: Jump statements: go to statement in C Programming language

Day 3: Jump statements: break statement in C Programming language

Day 3: Jump statements: continue statement in C Programming language

Day 4: Loops OR Iteration statement in C Programming language: for Loop

Day 4: Loops OR Iteration statement in C Programming language: while Loop

Day 4: Loops OR Iteration statement in C Programming language: do while Loop

Day 5: Array in C Programming language

Day 5: Access elements of Array in C Programming language

Day 5: One dimensional Array representation in memory using C Programming language

Day 5: Two dimensional Array representation in memory using C Programming language

Day 5: Multidimensional Array in C Programming language

Day 6: Function in C Programming language

Day 6: Definition, Declaration and Calling a Function in C Programming language

Day 6: Passing array to a function in C Programming language

Day 6: Calling Function in C Programming language : Call by value

Day 6: Calling Function in C Programming language : Call by reference

Day 6: Recursive Function in C Programming language

Day 6: Adding function to the library in C Programming language

Day 7: Pointer in C Programming language, How to use Pointer, Pointer declaration

Day 7: NULL Pointers in C Programming language

Day 7: Array of Pointers in C Programming language

Day 7: Pointer arithmetic in C Programming language

Day 7: Pointer to Pointer in C Programming language

Day 7: Pointer to Function in C Programming language: Passing pointers to functions

Day 7: Pointer to Function in C Programming language: Return pointer from functions

Day 8: Strings in C Programming language, Declaring String in C Programming language

Day 8: String functions in C Programming language

Introduction of Structure

Accessing the members of Structure

Structure With typedef Keyword and Use of sizeof function

Example of Structure

Dynamic memory allocation in C: Introduction

adplus-dvertising
Day 7 Passing pointers to functions in C Programming language
Previous Home Next

The function pointer is a powerful feature in c. In memory a function has a physical location that can be assigned to a pointer. This address is the entry point of the function and it is the address used when the function is called. Once a pointer points to a function, the function can be called through that pointer. Function pointers also allow functions to be passed as arguments to other functions or function pointers is a pointers, that point to the address of a function.

Now we can se that when we run the any program than that running program gets a certain space in the main-memory. than the executable compiled program code and variables are put inside this memory. Thus that program code have a functions than that function in the program code is, like e.g. a character field, nothing else than an address. It is only important how you, or better your compiler/processor, interpret the memory a pointer points to.

# Passing pointers to functions in C

#include <stdio.h>
 
/* function declaration */
double calAverage(int *ary, int sz);
 
int main ()
{
   /* an int array with 5 elements */
   int price[5] = {1000, 2, 3, 17, 50};
   double ag;
 
   /* pass pointer to the array as an argument */
   ag = calAverage( price, 5 ) ;
 
   /* output the returned value  */
   printf("Average value is: %f\n", ag );
    
   return 0;
}

double calAverage(int *ary, int sz)
{
  int    i, sum = 0;       
  double ag;          
 
  for (i = 0; i < sz; ++i)
  {
    sum += ary[i];
  }
 
  ag = (double)sum / sz;
 
  return ag;
}
Output

Average value is: 214.400000

Previous Home Next