1.Linux under the first C program, console print a word.
1VI first.c//Linux New File2 3#include <stdio.h>4 5 intMain () {6printf"Welcome to Linux, this is the first C program!"); 7 return 0;8 }9 TenCompile; Gcc-o First first.c//Linux compiled files OneExecution:./first//Linux Execution Files
2. The second C program: Understand the structure of the C program and realize the addition of two integers.
1 VI second.c2 3#include <stdio.h>4 intMain () {5 intx, y, sum;6x = - ;7y = $ ; 8sum = x +y;9printf"sum is%d", sum);Ten return 0; One } A //the Compile execution command is the same as the first C program.
3. Number of bytes in shaping data
1#include <stdio.h>2 3 intMain () {4 Short inti;5 intJ;6 Long intK;7 inta,b,c;8A =sizeof(i);9b =sizeof(j);Tenc =sizeof(k); One Aprintf"A is%d\n", a); -printf"B is%d\n", b); -printf"C is%d\n", c); the - //return 0; don ' t write return is OK? - } - Output: +A is 2 -B is 4 +C is 4
4. Floating-point data in bytes, floating-point number scale limit
1#include <stdio.h>2 3 intMain () {4 floati;5 DoubleJ;6 intA, B;7A =sizeof(i);8b =sizeof(j);9printf"A is%d \ n b is%d \ n", A, b);//bit numberTen One A floatc =88888.88888; - DoubleD =88888888888.88888888; -printf"c is%f \ n d is%f \ n", c,d);//%f decimals up to six bits the - } - - Output: +A is 4 -B is 8 +C is 88888.890625 //I is a single-precision floating-point number with a valid number of digits of 7, integers occupying 5 bits, decimals being 2 bits, second bit rounding results, and trailing invalid numbers AD is 88888888888.888885//J Double Precision, valid 16-bit, integer accounted for 11 bits, decimals accounted for 5 bits, followed by invalid number.
5. Character type data
1 //C language characters with ' single quote: eg: ' A '2 //escape character: \ n, newline, equivalent to enter3 //\ t, jumps to the next tab position, which is equivalent to the TAB key4 //\b, backspace, moves the current position to the previous column, which is equivalent to backspace5 //\ \, backslash character6 //\ ', single quote character7 //\ ", double quote character8 //A, null character, used in a string9 //\DDD, one to three-bit 8-binary-represented characters, such as \101 for character aTen //\xhh,1 to 2-bit hexadecimal representation of a character, such as \x41 for character a One //character variable definition: char c1, c2 = ' A '; occupies 1 bytes, 8bit, ' \ n ' is an escape character A -#include <stdio.h> - the intMain () { - intC1, C2; - CharC3; -printf"C3 is%d \ n",sizeof(C3)); + -C1 ='a'-'A'; +C2 ='b'-'B'; AC3 ='C'- +; at -printf"C1 is%d and C2 is%d \ n", C1, C2); -printf"C3 is%d and%c \ n", C3,C3); - return 0; - } - in - Output: toC3 is 1 +C1 is +and C2 is + -C3 is theand C
Linux C Program (one)