在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