【ubuntu操作系统】ubuntu系统下第一个C语言程序

来源:互联网 发布:流程优化再造的意思 编辑:程序博客网 时间:2024/06/06 06:45


转自:Ubuntu下编译第一个C程序的成功运行(测试可用)

对于每个新手来说,进入Ubuntu最想做的事莫过于在终端(Terminal)里运行自己的第一个C/C++程序"hello.c/hello.cpp"了。

很多语言书籍都是默认搭载好运行环境的,而Ubuntu默认是不包含编辑器vim和编译器gcc。假设你和我一样,展现在自己眼前的是一台刚安装好的Ubuntu电脑,下面我们将来实现自己的第一个程序。

1.准备工作

1.1 打开控制台:使用快捷键 Ctrl + Alt + T;

1.2 安装vim:输入 sudo apt-get install vim;

1.3 安装gcc:输入 sudo apt-get install g++。

2.编写hello.c源代码

2.1 新建文件名为hello.c的源文件:输入vim hello.c;

2.2 键入i 进入insert模式(即编辑输入模式),写入如下经典代码:

//the first program hello.c#include<stdio.h>int main(void){  printf("Hello, world!\n");   return 0;}

2.3 输入完成后,Esc 回到normal模式,键入:wq 保存退出vim。

3.编译hello.c

在终端执行  g++ hello.c -o hello 编译。

4.运行程序hello

./hello 就看到结果:

Hello,world!

Ubuntu下编译C程序的详解 http://www.linuxidc.com/Linux/2012-11/73360.htm

Ubuntu下编译和执行C程序  http://www.linuxidc.com/Linux/2009-10/22312.htm

Linux下用GCC编写第一个C程序 http://www.linuxidc.com/Linux/2011-07/38415.htm

更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-05/101844.htm


0 0
原创粉丝点击