新聞中心
請問matlab有沒有類似于C語言的入口主函數(shù)main()??
你在M文件中定義一個函數(shù),這個函數(shù)就就開始執(zhí)行,函數(shù)可以嵌套使用,你可以在此函數(shù)中調(diào)用其他M文件的函數(shù),也基本詳單與main函數(shù)吧。呵呵
創(chuàng)新互聯(lián)公司,為您提供成都網(wǎng)站建設(shè)、成都網(wǎng)站制作公司、網(wǎng)站營銷推廣、網(wǎng)站開發(fā)設(shè)計,對服務(wù)石雕等多個行業(yè)擁有豐富的網(wǎng)站建設(shè)及推廣經(jīng)驗。創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)公司成立于2013年,提供專業(yè)網(wǎng)站制作報價服務(wù),我們深知市場的競爭激烈,認(rèn)真對待每位客戶,為客戶提供賞心悅目的作品。 與客戶共同發(fā)展進(jìn)步,是我們永遠(yuǎn)的責(zé)任!
C#語言里有類似C語言里的main函數(shù)一類的東西沒有?如果有,他們的不同點是什么?
首先,C#中可以選擇不同的模版。這里舉我熟悉的例:
1、在控制臺應(yīng)用程序,控制臺運行時和C語言一樣,都是cmd黑色窗口,下面是例子(代碼寫在Program.cs里)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("輸入自己的學(xué)號");
string r = Console.ReadLine();
if (r == "123")
{
Console.WriteLine("姓名:張三");
Console.WriteLine("專業(yè):計算機");
Console.WriteLine("愛好:羽毛球");
Console.WriteLine("性格:安靜");
}
else
Console.WriteLine("輸入學(xué)號有誤!");
}
}
}
2、在Windows窗體運用程序中,Program.cs 是程序入口。當(dāng)你選擇是窗體應(yīng)用程序時,Program.cs里的代碼是自動就有的,不像上面的例子——Program.cs代碼是自己寫的。你自己要寫的代碼寫在其它窗體里,比如Form1、Form2.......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace P記事本
{
static class Program
{
/// summary
/// 應(yīng)用程序的主入口點。
/// /summary
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());//這里默認(rèn)是Form1,你自己要改也是可以的,這決定你的應(yīng)用程序執(zhí)行時,最先出現(xiàn)的是哪個頁面
}
}
}
綜上所述,可以看出是有類似C語言的main()函數(shù),區(qū)別你再細(xì)看。
C#中form1.cs和form1.Designer.cs前一個是設(shè)計語言代碼,第二個呢?form1.cs正確而form1.Designer.cs錯誤
program.cs是程序入口,也就是Main函數(shù)。
form1.cs是實現(xiàn)功能的代碼,包括你的自定義方法和事件。
form1.Designer.cs是你的畫面的設(shè)計代碼,一般由系統(tǒng)自動生成,也可以手動修改,嚴(yán)格意義上講,把這部分代碼拿到其他文件里也一樣可以,不強制。
你刪的那句是關(guān)聯(lián)一個label的Click事件的,因為你form1.cs里沒寫這個labelshouru_Click
方法,所以出錯,你刪除了,就不關(guān)聯(lián)這個事件了,所以就好了。
一般都寫在form1.cs里,因為寫到別的文件里會存在調(diào)用其他類對象的問題,相對比較麻煩。但一些共通的方法可以抽出到一個單獨的文件里,供整個工程調(diào)用。
C語言中入口參數(shù)是什么
以下以 C 語言為例,其余語言與之有類似之處:
A function is uniquely represented by a name and a set of operand types.
Its operands, referred to as parameters, are specified in a
comma-separated list enclosed in parentheses. The actions that the
function performs are specified in a block, referred to as the function
body. Every function has an associated return type.
函數(shù)由函數(shù)名以及一組操作數(shù)類型唯一地表示。函數(shù)的操作數(shù),也即形參,在一對圓括號中聲明,形參與形參之間以逗號分隔。函數(shù)執(zhí)行的運算在一個稱為函數(shù)體的塊語句中定義。每一個函數(shù)都有一個相關(guān)聯(lián)的返回類型。
As an example, we could write the following function to find the greatest common divisor of two ints:
考慮下面的例子,這個函數(shù)用來求出兩個 int 型數(shù)的最大公約數(shù):
// return the greatest common divisor
int gcd(int v1, int v2)
{
while (v2) {
int temp = v2;
v2 = v1 % v2;
v1 = temp;
}
return v1;
}
Here
we define a function named gcd that returns an int and has two int
parameters. To call gcd, we must supply two int values and we get an int
in return.
這里,定義了一個名為 gcd 的函數(shù),該函數(shù)返回一個 int 型值,并帶有兩個 int 型形參。調(diào)用 gcd 函數(shù)時,必須提供兩個 int 型值傳遞給函數(shù),然后將得到一個 int 型的返回值。
————C++ Primer 4th Edition
可以將形參理解為入口參數(shù),返回值理解為出口參數(shù)
話說,現(xiàn)在應(yīng)該基本上不使用“入口參數(shù)”/“出口參數(shù)”這樣的說法了吧
int main, voit main, scanf, printf各自用于什么
main函數(shù)是C,C++的入口函數(shù)。
如果你想讓你的main函數(shù)有返回值,那么需要用int main
如果你不想讓你的main函數(shù)有返回值,那么需要用void main
scanf是C語言里的輸入函數(shù),比如你用鍵盤輸入了數(shù)字12
int input = 0;
scanf("%d", input);
這樣input的值就變成了你輸入的12.
對于整型輸入,要用%d,對于float型,要用%f,而double型則用%lf.
printf正好和scanf的功能相反,是輸出函數(shù),又稱為打印函數(shù)。
輸出的格式與scanf是相同的。如:
int input = 12;
printf("%d", input);
分享標(biāo)題:類似c語言的入口函數(shù) c程序的入口函數(shù)
轉(zhuǎn)載來于:http://fisionsoft.com.cn/article/docoded.html