Giter Club home page Giter Club logo

exercise's Introduction

Intro

A repo for programming exercise.

Log

  • 2024/03/09
    • Start c programming exercise based on Learn C The Hard Way (Chiniese Version) .
    • c/ex1: Compile an example for printing "hello world".
    • c/ex2: Simple example of make and Makefile
    • c/ex3: Print with format, and try to make it error/crash, through methods like: not initializing varialbes, not specifying variables in the print command.
  • 2024/03/10
    • c/ex4: Install valgrind and use it for printing errors of exeutable.
      • Use curl -O <link> download the compressed .tar.bz2 file. Failed to uncompress with tar xvzf <file> at first with message bzip2: (stdin) is not a bzip2 file.... Root cause is found to be file is broken during downloading, which could be checked by md5sum comparison with that in the download page. Re-downloaded and then fixed.
      • How to change shell of make: By default, make use the POSIX shell (/bin/sh), need to add SHELL := /bin/bash on the top of Makefile to let it use bash. (Ref.)
      • How to pass args to make: (Ref.)
        • Makefile:
          run:
              @echo $(ARGS)
          
          run: make run ARGS="Hello", output: Hello
    • c/ex5: Read a simple c script line by line to know the basic code structure.
    • c/ex6: A script containning multiple variables of different data types. Print them with printf.
    • c/ex7: A simple code for knowing different types of data.
      • 'long' type integer:
        • printf with %ld
        • limit: -2^63 ~ +2^63 - 1
      • printf special char '\0' (null_byte) with:
        • %c -> (empty)
        • %s -> (null)
        • %d -> 0
      • printf char of number zero '0' with %s -> Segmentation fault
      • 'unsigned long' type integer:
        • printf with %lu
        • limit: 0 ~ +2^64 - 1
  • 2024/03/23
    • c/ex8: Play with array of numbers, array of chars and string by printf / sizeof
      • string is array of chars ending with null character, i.e. '\0'.
      • sizeof() returns the allocated memory for the operand, so, for a string, it will take the ending null into count, then usually looks 1 more than the number of characters of the string. (Ref.)
    • c/ex9: Involve something like array initialization, assigning string with pointer ... (Not really know what the author wants readers to know....just go through ๐Ÿ˜…:)
    • c/ex10: Array of strings and loop
      • argv[0] is the command/executable itself.
      • Format of a for loop:
        for(INITIALIZER; TEST; INCREMENTER) {
            CODE;
        }
        
        Executing order: INITIALIZER, TEST, CODE, INCREMENTER, TEST, CODE, INCREMENTER, ... until TEST being false.
  • 2024/03/24
    • c/ex11: While loop
      • Format of a while loop:
        while (TEST) {
            CODE;
        }
        
      • Usually for loop is more robust, since it has INITIALIZER and INCREMENTER that help avoiding errors.
      • Way to print the memory address of a variable:
        int var = 0;
        printf("Mem addr of var: %p \n" &var);
        
        output example: Mem addr of var: 0x7ffe2333ce7c
      • 1 byte = 8 bit
        • int -> 4 byte : 2^32 counts , -2^31 ~ +2^31 -1
        • char *[] -> 8 byte : 63 chars + 1 null
    • c/ex12: if - else conditional statement.
      • Better do not omit the curly braces {} for conditional statements.
    • c/ex13: switch statement
      • Compiler will convert it into a jumping table.
      • Don't forget break and default

exercise's People

Contributors

yuanhes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.