Search
 
SCRIPT & CODE EXAMPLE
 

C

C Passing Pointers to Functions

#include <stdio.h>

void addOne(int* ptr) {
  (*ptr)++; // adding 1 to *ptr
}

int main()
{
  int* p, i = 10;
  p = &i;
  addOne(p);

  printf("%d", *p); // 11
  return 0;
}
Comment

c function pointer in argument

void f(void (*a)()) {
    a();
}

void test() {
    printf("hello world
");
}

int main() {
     f(&test);
     return 0;
}
Comment

Passing pointer to function

#include <stdio.h>
   
void getDoubleValue(int *F){
   *F = *F + 2;
   printf("F(Formal Parameter) = %d
", *F);
}
  
int main(){
   int A;
   printf("Enter a numbers
");
   scanf("%d", &A);
   /* Calling function using call by reference */
   getDoubleValue(&A);
   /* Any change in the value of formal parameter(F)
   will effect the value of actual parameter(A) */
   printf("A(Actual Parameter) = %d
", A);
     
   return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: stack push code 
C :: how to get the ascii value of a character in c 
C :: c recursion func revers number 
C :: malloc c include 
C :: print a part of string c 
C :: compare c strings 
C :: C program to check whether character is lowercase or not using ASCII values 
C :: How to Convert double to int in C 
C :: adding strings in the list 
C :: c program to find the frequency of characters in a string 
C :: c find last element in array 
C :: pointers to a function in c 
C :: identifiers in c 
C :: unsigned char c programming 
C :: replace a substring with another substring in c 
C :: How to copy one string into another in C 
C :: C program to input the month number and output the month name using switch statement 
C :: how to insert elements in and array and print it in c 
C :: how to print % in c 
C :: c read binary file 
C :: c unused variable 
C :: declaration of string in c 
C :: c malloc 
C :: 2 html 1 javascript 
C :: Here is a program in C that illustrates the use of fprintf() to write a text file: 
C :: semicolong after for() loop stackoverflow 
C :: how to link flexslider 
C :: counting sort using malloc and size-t type c 
C :: C Change Value of Array elements 
C :: pre-commit configuration 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =