Review the first day of C language

Source: Internet
Author: User
Tags value of pi

1, short-circuit operation # include <stdio.h>void main1 (void)
{
Short-circuit operation, logic and operator, if left operand is false, right operation number is shorted
int a = 5;
if ((4 < 3) && (A = 2))
if ((4 > 3) && (A = 2))
printf ("11111111111\n");
Else
printf ("00000000000\n");

printf ("%d\n", a); GetChar ();
}void Main (void)
{
int a = 5;
Logic or caused by short-circuiting operation, left operand true, no need to perform judgment right operand
if ((4 > 3) | | (A = 2))
printf ("11111111111\n");
Else
printf ("00000000000\n"); printf ("%d\n", a); GetChar ();
}2, sum of three doubles, square sum, square sum (compile gcc xxx.c-o x-lm) (-LM connection database) #include <stdio.h>
#include <math.h>void main (void)
{
Double A = 1.0;
Double b = 2.0;
Double c = 3.0; Double A = 1.0, B = 2.0, c = 3.0;
Double result; result = a + B + C;
printf ("%f\n", result); result = A*a + b*b + c*c;
printf ("%f\n", result); result = sqrt (result);
printf ("%f\n", result); GetChar ();
}3 Conditional statement # include <stdio.h>void main (void)
{
int a = 3;  scanf_s ("%d", &a); 6//if (A > 5)
A + = 2;
Else
a--;
(A > 5)? (A + = 2): (a--);
Judgment for true execution for false execution
printf ("%d\n", a);   GetChar (); ' \ n '
System ("pause"); Use of SACNF () # include <stdio.h>void main (void)
{
int num;
scanf_s ("%d", &num); if (8 = num)
printf ("11111111111\n");
Else
printf ("00000000000\n");
GetChar ();} Escape character memory How to store data or instructions

A variable is a quantity whose value can vary. In the computer, instruction code and data are stored in memory. Variables also need to be stored in memory. In a computer, each variable is allocated a piece of memory space where the value of the variable is stored. Variables can change, that is, this storage space can store different values. The value in the storage space changes, the value corresponding to the variable also changes. At the same time, only one copy of the value is saved in the memory space, and the new value flushes out the old value. Each memory unit has a number, which is the address of the memory.

Variable-named rule identifiers
Definition: A sequence of characters used in a program to identify constants, variables, functions
Composition
Can only consist of letters, numbers, underscores, and the first letter must be a letter or an underscore
There's a difference in capitalization.
Cannot use the C language keyword
Rules:
See the name of the idea
It is not appropriate to confuse defining variables

A variable is the amount of value that can be changed during the execution of a program. A variable has a name, called a variable name, represented by an identifier.

Define the format of the variable:
Type name variable name, variable name, ..., variable name;
such as: int a,b,c;
float x, y, Z;
Char ch;
The definition of a variable is generally written at the beginning of the function, and multiple variables are separated by commas. What is the wording of a variable?

C Language Provisions:
All variables must be defined before they are used

Why variables must be initialized,

If the variable is not initialized, it can be compiled successfully, but when executed, it is likely to error.
How the operating system manages memory!
Whenever an application is opened, the operating system allocates memory for it, memory addresses and memory units, and when the application initializes, it writes data to the memory unit, and when the operating system recycles, it does not empty the memory unit, so there is a lot of junk data.
If the variable is not initialized, the garbage data is read by default, and some junk data can cause the program to crash.
vc++2010 compiler can be aware that the variable is not initialized, debugging will be error.
Therefore, the variables must be initialized before they are used.

There are two ways to define constants to define a constant pi:
1. #define PAI 3.14159;
2. Const float PAI 3.14159;
Difference:
The first way: is to define PI as a symbol, at this time Pai is only 3.14159 alias, during compilation with 3.14159 to replace the value of pi, define equivalent to replace.
The second way: the PI is defined as a variable, but tells the compiler that its value is fixed, if in the program to try to modify its value, at compile time will error;
#define定义常量有什么好处呢
(1) By means of meaningful word symbols, the meaning of the constant can be specified, allowing programmers to reduce confusion when reading the code.
(2) Need to modify the constant, you can only need to modify once, to achieve batch modification, high efficiency and accurate.
If you need to modify PI to 3.14, you only need to change the line of code:
#define PI 3.14159
For
#define PI 3.14

Review the first day of C language

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.