C language----basic data types and basic operations iOS learning-----Fine-grained knowledge points summary

Source: Internet
Author: User

Import header file (stdio.h), header file for standard input and output,
#include <stdio.h>

Entrance to the program
int main (int argc, const char * argv[]) {
Insert code here ...
printf ("Hello, world!\n");

This is a single-line comment, comment out a line of code, the commented out code will not be executed, just do an identity role. Annotations are essential in the process of coding, and the purpose of writing comments is to work on the handover and teamwork, on the other hand to give yourself a hint. Comments can also take the code we don't currently use, but the code that might be used in the future will not compile for the time being. A valid comment in a project should account for 60% of the code.
/*
This is a multiline comment that can comment out more than one line of code, and this part of the code will not execute
*/
Byte is the smallest unit stored in a computer, and unsigned 1byte can represent a number range of 0~255,1byte = 8bit bits
/*
Variable has three-part type modifier variable name = initial value
Defines a variable, age, which is used to represent the ages, the type is int, and the initial value is 25.
int age = 25;
Define a variable string, type char, initial value ' a '
Char string = ' A ';

Naming conventions for variables: 1, only numbers, characters and underscores, and numbers cannot begin;
int _number = 3;
int good = 5; The variable name can be used in Chinese, but it is strictly forbidden to use it in development.
2, cannot and system keyword (reserved word) duplicate name
int int = 4;
3. Variable names cannot be duplicated
int age = 30;
4, the name of the variable should be standardized, so as to see the name of the idea
int number1 = 3;
int number2 = 5;
*/
int NUM1 = 501;
float num2 = 2.0;
float num3 = num1/num2; If both sides of the "/" are integers, then their results are integers.

Modulo operation '% ', take the remainder operator
int NUM1 = 5;
int num2 = 3;
int num3 = num1% num2;
Self-increment operation "+ +", self-subtraction operation "--"
num3 = num1++; This line of code is equivalent to assigning the value of NUM1 to num3 (num3 = NUM1;) and then adding the NUM1 to 1, assigning the result to num1 (NUM1 = num1 + 1;)

num3 = ++NUM1; This line of code is equivalent to the first NUM1 plus 1, the result is assigned to NUM1 (NUM1 = num1 + 1;), and then the value of NUM1 is assigned to num3 (num3 = NUM1;)


Num2 + = NUM1;

Two operators: arithmetic operator assignment operator, precedence: arithmetic operator > Assignment operator
NUM3 = (num1++ + ++num2) * 3;


Formatted output function printf ()

float age = 27.1;
printf ("Age =%f\n", age); Formatted output function, normal character output, if you want to output the value of the corresponding variable, then you need to use the corresponding escape character (conversion)

char sex = ' m ';
printf ("Sex is:%c\n", sex);

Short NUM1 = 30;
printf ("%hd\n", NUM1);

Long num2 = 20;
printf ("num2 =%ld\n", num2);

unsigned long integer type
unsigned long num3 = 100;
printf ("num3 =%lu\n", num3);

printf ("%4d\n", 122);

printf ("%.2f\n", 2.223);

printf ("%-4d\n", 12); Align Left

%M.NF, if the total number of outputs of the output is greater than M, then the decimal point in front of the original output, the decimal place after the N-bit, if the n+1 and then the number of digits less than m, then the output of the first fill space
printf ("%10.2f\n", 12.3345);

' \ n ' is a newline character.
printf ("\ \ \ \"); If you want to output ' \ ', you need to use ' \ \ '
printf ("100%%\n"); If you want to output '% ', then you need to use two ' percent '

Format input function scanf ()

Define variables NUM1 and num2 to receive numbers entered from the console
int NUM1 = 0;
int num2 = 0;
printf ("Please enter two digits, separated by a space between the numbers:");
scanf ("%d%d", &NUM1, &num2); ' & ' take address symbol
GetChar (); Remove a character from the keyboard buffer
printf ("Num1 =%d, num2 =%d\n", NUM1, num2);

Char string = ' 0 ';
printf ("string =%c\n", string);
printf ("string =%d\n", string);

scanf ("%c", &string);
GetChar (); Remove a character from the keyboard buffer

printf ("Stringa =%d", string);



return 0;

C language----basic data types and basic operations iOS learning-----Fine-grained knowledge points summary

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.