Skip to content

Lecture 01

Linux

C

hello.c
/* File: hello.c
 * -------------
 * This program prints a welcome message to the user.
 */

#include <stdio.h> // for printf

int main(int argc, char * argc[]) {
    printf("Hello, World!\n");
    return 0;
}

工作流程

  • ssh
  • vim / emacs
  • gcc
  • gdb
args.c
/* args.c
 * ------
 * This program prints out information about its received
 * command-line arguments.
 */

#include <stdio.h>

int main(int argc, char* argv[]) {
    printf("This program received %d argument(s)\n", argc);
    for (int i = 0; i < argc; i ++ ) {
        printf("Argument %d: %s\n", i, argv[i]);
    }
    return 0;
}

printf

printf(format_string, arg1, arg2, ...);
  • print format
  • console output
  • placeholder 格式化占位符
    • %s - string
    • %d - integer, decimal
    • %f - double, float
    • %p - pointer

bool

C99
#include <stdbool.h>

bool flag = true;
flag = false;

推荐阅读