zoukankan      html  css  js  c++  java
  • <C Primer Plus >2 Altering Variables in the Calling Function

     1 #include <stdio.h>
     2 int diff(int x, int y);//the first form
     3 void interchange(int *u, int *v);//the second form
     4 int main(void){
     5     int x = 9;
     6     int y = 5;
     7     int z;
     8     printf("The Originally x = %d and y = %d
    ", x, y);//alter variables in the calling function
     9     interchange(&x, &y);
    10     z = diff(x, y);//need a value for some calculation or action
    11     printf("Now  x = %d and y = %d
    ", x, y);
    12     printf("z = %d
    ", z);
    13     return 0;
    14 }
    15 
    16 int diff(int x, int y){
    17     return(x - y);
    18 }
    19 
    20 void interchange(int *u,int *v){
    21     int temp;
    22 
    23     temp = *u;
    24     *u = *v;
    25     *v = temp;
    26 }

    int function1(int x);

    int function2(int *ptr);

    Remeber:

    1 Use the first form if the function needs a value for some calculation or action;

    2 Use the second form if the function needs to alter variables in the calling function.

      One function does not have direct access to variables declared in another function. If you do need one function to acess another function's data,you can use pointer function arguments.

  • 相关阅读:
    MobileNet V1 V2
    异常检测 与 One Class SVM
    异常检测
    图像分割
    1x1卷积核的作用
    迁移学习
    python
    图像分割
    图像分割
    Nagios
  • 原文地址:https://www.cnblogs.com/michael2016/p/6580684.html
Copyright © 2011-2022 走看看