由Kernighan和Ritchie合著的经典教程《The C Programming Language》的开篇***个C程序例子是打印简单的“hello world”。从此之后,“hello world”就成了描述一个人编写的***个程序的代名词——不论是什么语言技术,即使实际上程序并没有在字样上输出“hello world”几个字。

创新互联主营中原网站建设的网络公司,主营网站建设方案,app软件开发公司,中原h5微信小程序定制开发搭建,中原网站营销推广欢迎中原等地区企业咨询
对于初学者来说,这“hello world”程序是让人恐怖的。他会想“我一定非常笨,连这入门的hello world程序都觉得难。照这样下去,我一定不会喜欢上编程。”
其实,这问题的原因是我们把“***个”和”最简单的一个“混淆了。“hello world”程序可以是任何的程序,没有难易限制。当你***次编程时,你不知道该用哪种编译器、不知道代码文件应该放到哪里、不知道它们应该是什么格式,等等。你需要去学。大量的知识在你真正能够编程前都需要学习、慢慢的学会 。
本文的作者 John D. Cook
当我最初开始学习编程时,我总希望能尽快的越过写“hello world”程序的阶段,希望能够立刻开始编写真正有用的程序。但事实上,我发现我大半辈子时间都在写“hello world”程序,而且看不到结束的尽头。
每当讨论起“hello world”程序,几乎避免不了的要说一说这世界上最恐怖的“hello world”程序:Charles Petzold在他的《Programming Windows》一书中描述的***个Windows程序。我只能找到这本书的Windows 98版的。不知道它跟最初的原版有多大区别,但我印象里原版里的代码会比现在这个更恐怖。
- /*------------------------------------------------------------
 - HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
 - (c) Charles Petzold, 1998
 - ------------------------------------------------------------*/
 - #include
 - LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
 - int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
 - PSTR szCmdLine, int iCmdShow)
 - {
 - static TCHAR szAppName[] = TEXT ("HelloWin") ;
 - HWND hwnd ;
 - MSG msg ;
 - WNDCLASS wndclass ;
 - wndclass.style = CS_HREDRAW | CS_VREDRAW ;
 - wndclass.lpfnWndProc = WndProc ;
 - wndclass.cbClsExtra = 0 ;
 - wndclass.cbWndExtra = 0 ;
 - wndclass.hInstance = hInstance ;
 - wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
 - wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
 - wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
 - wndclass.lpszMenuName = NULL ;
 - wndclass.lpszClassName = szAppName ;
 - if (!RegisterClass (&wndclass))
 - {
 - MessageBox (NULL, TEXT ("This program requires Windows NT!"),
 - szAppName, MB_ICONERROR) ;
 - return 0 ;
 - }
 - hwnd = CreateWindow (szAppName, // window class name
 - TEXT ("The Hello Program"), // window caption
 - WS_OVERLAPPEDWINDOW, // window style
 - CW_USEDEFAULT, // initial x position
 - CW_USEDEFAULT, // initial y position
 - CW_USEDEFAULT, // initial x size
 - CW_USEDEFAULT, // initial y size
 - NULL, // parent window handle
 - NULL, // window menu handle
 - hInstance, // program instance handle
 - NULL) ; // creation parameters
 - ShowWindow (hwnd, iCmdShow) ;
 - UpdateWindow (hwnd) ;
 - while (GetMessage (&msg, NULL, 0, 0))
 - {
 - TranslateMessage (&msg) ;
 - DispatchMessage (&msg) ;
 - }
 - return msg.wParam ;
 - }
 - LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 - {
 - HDC hdc ;
 - PAINTSTRUCT ps ;
 - RECT rect ;
 - switch (message)
 - {
 - case WM_CREATE:
 - PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
 - return 0 ;
 - case WM_PAINT:
 - hdc = BeginPaint (hwnd, &ps) ;
 - GetClientRect (hwnd, &rect) ;
 - DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
 - DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
 - EndPaint (hwnd, &ps) ;
 - return 0 ;
 - case WM_DESTROY:
 - PostQuitMessage (0) ;
 - return 0 ;
 - }
 - return DefWindowProc (hwnd, message, wParam, lParam) ;
 - }
 
                标题名称:“Helloworld”不简单
                
                转载来源:http://www.csdahua.cn/qtweb/news28/203528.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网