an example

一个小而精的例子,对于10个数的排序:

/* 标准文档模板 */^

#include "Stdio.h"
#include "Conio.h"
static int D=0;
int main(void)
{
 /* 此处添加你自己的代码 */
 int value,count,max;
 int compare(int);
 printf("输入10个数用于排序:/n");
 scanf("%d",&D);
 for(count=0;count<9;count++)
 {
     scanf("%d",&value);
     max=compare(value);
 }
 printf("%d/n",max);
  getch();
  return 0;
}
int compare(int t)
{

   if(t>D)
   {
    D=t;
    return t;
   }
   return D;

又一个小程序:

/* 标准文档模板 */

#include "Stdio.h"
#include "Conio.h"


int main(void)
{
    void get();
 /* 此处添加你自己的代码 */
  get(0);
  getch();
  getch();
  getch();
  return 0;
}
void get(int n)
{
    static int i=1;
    char a;
    if(i%6==0)
    {
        return ;
    }
    else
    {   a=getch();
        putch(a);
        get(i++);
        putch(a);
    }

}

变量:变动的理,常量:不变动的量

我们对变理赋值是将值赋给内存中(由我们定义的这个变量的内存单无中),如果要细说清楚的话,要用到汇编(所以在这里不在更深说明),只要记住就行了,例如:

int a=100;赋值就后我们定义的变量a这个内存单元的内容就是100,

int *p=100;这个就要想到的是指针的类型了,变量名p的类型是int *(请记住,如果对这方面的可以看一看指针之类的资料),变量p这个内存单元中的内容就是100,但是*p=280001就是他所指向的内存单元(那就另当别论)

int **p=100;这个也同上,但是分开的话,那就是描述是两个对象(姑且这样理解吧^_^)那就是p和*p是两个指针,现在我们定义的内存单元为p的内容为100,他(p)指向的内*p=28001(姑且算这个值吧),而(*p)所指向的内容就是**p=0(最终内存单元,他没有指其他内存单元的能力了)

初学者还可以看一看转载的东西(什么是指针,更近一步理解).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure! Here's an example to explain the concept of "passing by value" in C++: ``` #include <iostream> using namespace std; void increment(int x) { x++; // increment the value of x cout << "Value of x inside the function: " << x << endl; } int main() { int num = 5; cout << "Value of num before function call: " << num << endl; increment(num); // passing num by value to the function cout << "Value of num after function call: " << num << endl; return 0; } ``` In this example, we have defined a function `increment` that takes an integer parameter `x`. Inside the function, we increment the value of `x` by 1 and print its value. In the `main` function, we define an integer variable `num` and initialize it to 5. We then print the value of `num`, call the `increment` function, and print the value of `num` again. When we pass `num` to the `increment` function, a copy of the value of `num` is created and passed to the function. This means that any changes made to `x` inside the function do not affect the value of `num` outside the function. So, even though we increment the value of `x` inside the function, the value of `num` remains unchanged outside the function. When we run the above code, the output will be: ``` Value of num before function call: 5 Value of x inside the function: 6 Value of num after function call: 5 ``` As you can see, the value of `num` remains unchanged after the function call, even though we incremented the value of `x` inside the function. This is because `num` was passed to the function by value, and any changes made to the value of `x` inside the function do not affect the value of `num` outside the function.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值