C language The first C language program and development tools

Source: Internet
Author: User

    1. Selection of development tools
    2. Tools you can use to write code: Notepad, UltraEdit, Vim,Xcode , etc.
    3. Reasons to choose Xcode: Apple's official development tool, simplified development process, highlighted features
    4. Use Xcode to create a new source code file for a C program (extension. C or. c)
    • Open Xcode

    • New file

    • Select the type of file

    • Enter a file name and a directory to select files for

    • New Complete

    • Delete all automatically generated content from the file, starting from zero

    1. Code writing
    1. Program Structure
      1. The structure of the C program: consists of functions
    • Any C language program is composed of one or more program segments (small programs), each of which has its own function, which we generally call "functions". So, you can say that the C language program is made up of functions

    1. Basic concepts of functions
    • Function name: an infinite number of functions in a program, each with its own name
    • Call (Execute) function: According to the function name can call the corresponding function, perform the corresponding function
    1. The entrance to the C program
    • The entrance to the C program is a function called main , referred to as the main function
    • Regardless of the number of functions in the program, the main function is executed first

    1. Writing Programs
      1. Write the main function (the contents of the curly braces {} are the body of the function)

int Main ()

{

return 0;

}

    1. write multiple functions , and make calls

int Test ()

{

return 0;

}

int Main ()

{

Test ();

return 0;

}

    1. Use the printf function to output content to the screen

#include <stdio.h>

int Main ()

{

printf ("Hello world!" );

return 0;

}

    1. Compile
    2. What is compiling: Translating C source programs into 0 and 1 that the computer can recognize
    3. What compiler to use: Xcode3 using GCC,XCODE4 with LLVM compiler (front end with clang)
    4. How do I compile a program using the Clang compiler?
    • In the terminal, enter: Cc–c file name. C
    • The compilation succeeds and the. O target file is generated
    1. Compiler Error and warning features
    • If the code has a syntax problem, the compiler will direct an error. and indicate the number of errors and the exact line number.
    • As long as there are 1 errors, the program will not compile successfully and will not generate an. o file
    • Warning messages are just some of the compiler's recommendations and do not affect compilation through

    1. Link
    2. What the link does: combine the. o file and the C-language function library to generate the executable file
    3. done by the linker, the Clang compiler already contains the link directive
    • In the terminal, enter: CC file name. O
    • Link succeeds, generates a.out executable file

    1. Run
    2. Two modes of operation
    • Directly double-click Open a.out File
    • Use the./a.out directive in the terminal
    1. After modifying the contents of the file, be sure to recompile, link, and then run
    2. \ n Function: Carriage return to newline

    1. Other clang instructions
    • Modify executable file name: CC xxx.o-o filename
    • Compile together, Link: cc xxx.c

    1. Common Mistakes for beginners
    • Do not write semicolons, use a Chinese semicolon
    • string with double quotation marks, or single quotes, double quotation marks inside.
    • The code is not written inside the main function, before the return
    • File extension is not. C or. c, e.g.. txt
    • Compile the file with absolute path, note where the target file is generated

    1. Summarize
    2. The process of running the whole program

    1. Summarize the extension of common Files
    • . c is a C language source file that is created when you write code
    • . O is the target file that is generated when the compilation is successful
    • . Out is an executable file that is generated when the link succeeds
    1. Summary clang directive
    • Compilation: Cc–c xxx.c
    • Link: cc XXX.O
    • Compile, Link: cc xxx.c
    • Run the executable file:./a.out
    1. What errors are encountered in development? How to solve?
    • Syntax error, can be resolved by compiler errors
    • Logic error, need to be patient to debug program
    1. Learning Advice
    • Learning to program is not learning English
    • Readability of the program
    • Beginners should not be too root to ask the bottom

    1. Exercises

Output the following pattern in 2 different code types

************

* * Itcast * *

************

Content Source: Preach intelligence podcast Li Mingjie teacher Content

C language The first C language program and development tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.