在jupyternotebook中写C/C++


在jupyter notebook中写C/C++,最大的好处就是不用写main()函数,直接调用写好的函数即可执行。

#include<stdio.h>
int sum(int a,int b){
    printf("a=%d,b=%d",a,b);
    return a+b;
}

当运行函数时后面可以不用加;,像python一样直接输出函数的返回值;

sum(2,3)
a=2,b=3




5

如果加了;,函数仍然可以正常运行,只是不会像上面一样直接输出结果。

sum(2,3);
a=2,b=3

在一个单元格里只能定义一个函数,若定义两个函数就会报错,

int sum1(int a,int b){
    return a+b;
}
int sum2(int a,int b){
    return a+b;
}
input_line_49:5:23: error: function definition is not allowed here
 int sum2(int a,int b){
                      ^



Interpreter Error: 



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM