Search
 
SCRIPT & CODE EXAMPLE
 

C

pass the pointer to the function

#include<stdio.h>

//pass the simple pointer to the function

void swapnum(int* i, int* j)
{
  	int tmp = *i;
  	*i = *j;
  	*j = temp;
}

int main()
{
  	int a = 10;
  	int b = 20;
  	swap(&a,&b);
  	printf("A is %d and B is %d
", a , b);
  	return 0;
}
Comment

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

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 :: oracle trunc 
C :: size of operator in c language 
C :: calling of a void in c 
C :: c program for assignment operator 
C :: what is the last character of a string in c 
C :: unused variable in c 
C :: how to declare a struct in c 
C :: *= in c 
C :: predefined macros 
C :: pipe system call 
C :: XAudio2 C 
C :: allocating memory for 1Mb text file in C 
C :: how to change the smartart style to 3D polished in powerpoint 
C :: ansi c function array of strings parameter 
C :: Talk about the difference between call by reference and call by value and in C language with example? 
C :: send an array through a pipe 
C :: OpenDaylight maven settings 
C :: code to reverse the words in a sentnce 
C :: C Change Value of Array elements 
C :: Entering raw mode 
C :: (avar == 1) ? (bvar == 2 ? result = 3 : (result = 5);) : (result = 0); 
C :: BEE/URI problem no 1181 solution in C 
C :: Example of header file c 
C :: Uri/Beecrowd problem no - 1149 solution in C 
C :: debian9 remove pack 
C :: can we use special characters in switch case in c 
C :: bucket sort 
C :: write to console c 
Dart :: debug banner flutter 
Dart :: flutter label align top 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =