C Summary 1

Source: Internet
Author: User
Tags array definition hypot

C-Summary

 

1. the development environment of C is Visual C ++ 6.0 SP6 Simplified Chinese version.

2. The standard input of C is:

For example, INTA = 0; % indicates an escape character.

Scanf (% d \ n, & A); & indicates the address. % D indicates that the input is of the int type.

Output: printf (% d, a); // output the value of. % D indicates that the output value belongs to the int type.

3. the const keyword is to limit that the variables defined by it are immutable.

4. Three basic data types of C: integer, floating point, and character.

5. the sizeof function is used to obtain the length of the data type.

6. The signed and unsigned modifiers indicate signed and unsigned, respectively. The signed modifier can be an integer, while the unsigned modifier can only be a non-negative integer.

7. The keyword typedof is used to create an alias for the data type, for example, typedof char mychar;

Mychar M = 'C ';

8. The keyword volatile is used to re-read this value every time when the compiler is optimized, rather than using the backup in the register.

9.% d represents an integer

% C represents a character

% F indicates float.

% Lf indicates double

10. array definition: int I [] = {1, 3, 5, 4}; (brackets cannot be placed before the variable .)

11. The definition of C functions is divided into two parts: function declaration and function body.

12. If you want to call C functions and put them under the main function, you must declare them on the main function before running the function, then you can only put the function on the main function.

13. function value passing is divided into three methods: Value passing, reference passing, and pointer passing.

14. Calculate the oblique edges of a right triangle.

# Include <stdio. h>

# Include <math. h> // header file of the math library

/* Functionprototype */

Double hypot (Double X, Double Y); // declare a function prototype.

 

Int main ()

{

Double side1, side2;

Printf ("enter 2 sides of right triangle \ n ");

Scanf ("% lf", & side1, & side2 );

Printf ("the hypotenuse is: % F \ n", hypot (side1, side2); // function call, call hypot.

//Real Parameters: The parameter actually passed to the function when the function is called.

// PrintReturn Value.

Return 0;

}

 

Double hypot (Double X, Double Y) // parameter: The function parameter when the function is declared or defined.

{

Return (SQRT (x * x + y * y); // returns the square function. You can use an expression as the real parameter passed during function calling.

// Use the value of the expression after return as the return value of the function.

// The type of the returned value, which must be consistent with the return value type declared in the function header.

}

 

 

15. inline functions: if an inline function is executed when the main function is executed, it will not jump to this function body for execution, instead, the code in the inline function is loaded into the function that calls the function to improve the running efficiency.

For example:

Inline int func (int A, int B)

{

Return A + B;

}

 

16. Function overload (C ++ exclusive)

The two functions have the same name and different parameters (different number of parameters and different parameter types) and become function overloading.

Different parameter lists.

Example

# Include <iostream>

Using namespace STD;

 

Int square (INTI)

{Return I * I ;}

 

Float square (floatf)

{Return f * F ;}

 

Int main ()

{

INTA = 2;

Floatb = 0.5;

 

Cout <"the square of" <A <"is" <square (a) <Endl;

Cout <"the square of" <B <"is" <square (B) <Endl;

Return0;

}

 

17, chara = 'q ';

// Declare a pointer variable

Char * P = & Achar; // P = 145600

18. output the value of a with the address

Int A = 5;

Int * P = &;

Int ** q = & P;

Int *** r = & Q;

Scanf ("% d", & );

Scanf ("% d", P );

Scanf ("% d", * q );

Scanf ("% d", ** R );

 

19,

For example:

Char C;

Char * PC;

Int;

Int * pA;

Double X;

Double * PX;

Print

Sizeof (c) = 1 sizeof (PC) = 4 sizeof (* PC) = 1

Sizeof (A) = 4 sizeof (PA) = 4 sizeof (* pA) = 4

Sizeof (x) = 8 sizeof (PX) = 4 sizeof (* px) = 8

 

20. Exercise code:

// Day03.cpp: defines the entry point for the console application.

//

 

# Include "stdafx. H"

# Include <math. h>

// Int HP (int A, int B );

// Void replace1 (int c, int D );

// Void change (int * a, int * B );

// Int square (int I );

// Float square (int f );

// Int * smaller (int * P1, int * P2 );

Void Replace (INT **, int **);

Void B (int A []);

Int main (INT argc, char * argv [])

{

// Int I = HP (1.0, 2.0 );

 

// Printf ("I = % d \ n", I );

 

/** Int c = 3;

Float d = 4.0f;

// Replace1 (c, d );

Int I = square (C );

Printf ("% d \ n", I );

Float F = square (C );

Printf ("% F \ n", F );

**/

/**

INTA = 5;

Intb;

Int * P1 = &;

Int * P2 = & B;

Int ** P3 = & P2;

Int *** P4 = & P3;

Floatx = 12;

Scanf ("% d", & B );

Scanf ("% d", P2 );

Scanf ("% d", * P3 );

Scanf ("% d", ** P4 );

Printf ("% d \ n", B, * P2, ** P3, *** P4 );

 

**/

 

 

 

// Printf ("% F \ n", X );

 

// Printf ("A = % d \ NB = % d \ n", a, B );

// Int * p = 0;

// P = smaller (P1, P2 );

// Printf ("% d \ n", * P );

/**

 

Int A = 1;

Int B = 2;

Int * P1 = &;

Int * P2 = & B;

 

Int ** P3 = & P1;

Int ** P4 = & P2;

 

Replace (P3, P4 );

 

Printf ("% d \ n", * P2 );

Printf ("% d \ n", * P1 );

**/

 

INTA [] = {1, 2, 5, 6, 7 };

 

B ();

 

Printf ("% d \ n", a [0]);

Return0;

}

 

Void Replace (INT ** P3, int ** P4 ){

Int * P;

P = * P3;

* P3 = * P4;

* P4 = P;

 

}

Void B (int A []) {

 

A [0] = 5;

}

// Int * smaller (int * P1, int * P2 ){

 

// Return (* P1 <* P2? P1: P2 );

 

//}

 

 

/** Void change (int * a, int * B ){

Int temp = 0;

 

Temp = *;

* A = * B;

* B = temp;

 

}

 

 

Int square (int I)

{Return I * I ;}

 

Float square (int f)

{

Return (float) F );

}

 

 

// Int HP (int A, int B ){

 

// Return (SQRT (A * A + B * B ));

 

//}

 

Void replace1 (int c, int d ){

 

Inttemp = 0;

Temp = C;

C = D;

D = temp;

Printf ("c = % d \ TD = % d \ n", C, D );

 

}

**/

 

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.