C语言英文版课件
perators
C has a set of ‘shorthand’ operators of the form: v op =exp; where v is a variable, exp is an expression op is a C binary arithmetic operator op= is known as the shorthand assignment operator v op =exp; is equivalent to v =v op (exp);
3.9 Special Operators
Pointer Operators: & and * Member Selection Operators: . and ->
The Comma Operator: can be used to link the related expression together. A comma-linked list of expressions are commaevaluated left to right and the value of right-most rightexpression is the value of the combined expression.
1. 2. 3. 4. 5. 6. 7. 8. Arithmetic operators. Relational operators. Logical operators. Assignment operators. Increment and decrement operators. Conditional operators. Bitwise operators. Special operators.
Op_1
Non_zero Non_zero 0 0
Op_2
Non_zero 0 Non_zero 0
Value of the Expression op_1&&op_2 op_1||op_2
1 1 1 1 1 1 1 1
Examples:
1. if (age > 55 && salary < 1000) 2. if (number < 0 || number > 1000)
The use of shorthand assignment operators has three advantages:
1. 2. 3. What appears on the left-hand side need not be repeated leftand therefore it becomes easier to write. The statement is more concise and easier to read The statement is more efficient
3.3 Relational Operators
C supports six relational operators in all: Operators Meaning
< <= > >= to == != is equal to is not equal to is less than is less than or equal to is greater than is greater than or equal
Example
4.5<=10 10<7+5 4.5<4.5<-10 a+b=c+d ? -35>=0
Relational Operator Complements
Among the six relational operators, each one is a complement of another operator. > is complement of <= < is complement of >= == is complement of != We can simplify an expression involving the not and the less than operators using the complements as shown below: Actual one Simplified one !(x<y) x>=y !(x>y) x<=y !(x!=y) x==y !(x<=y) x>y !(x>=y) x<y !(x==y) x!=y
3.2 Arithmetic operators
Operator
+ - * / %
Meaning
Addition or unary plus Subtraction or unary minus Multiplication Division Modulo division
Examples:
a-b, a+b, a*b, a/b, a%b
3.4 Logical Operators
C has the following three logical operators:
&& || ! meaning logical meaning logical meaning logical AND OR NOT
Example:
Truth Table
Examples: x+=y+1; x+=3; is equivalent to is equivalent to x=x+(y+1); x=x+3;
Shorthand Assignment Operators
Statement with simple assignment operator a=a+1 a=a–1 a = a * (n+1) a = a / (n+1) a=a%b Statement with shorthand operator a += 1 a -= 1 a *= n+1 a /= n+1 a %= b
– Example: value = (x = 10, y = 5, x + y); – value = 15; – Some applications of comma operator are: In for loops: for ( n = 1, m = 10, n <= m; n++, m++ ) In while loops: while( c = getchar( ), c != ‘10’ ) Exchanging values: t = x, x = y, y = t;
Example 3.1
The Program shows the use of integer arithmetic to convert a given number of days into months and days.
main() Output { int months, days; Enter days 265 printf(“Enter days\n”); Months=8 Days=25 scanf(“%d”, &days); Enter days months = days/30; 364 days = days % 30; Months=12 Days=4 printf(“Months=%d Enter days months, days); days=%d”, 45 } Months=1 Days=15
– a = 10; b = 15; x = (a > b) ? a : b; – if (a > b) x = a; else x = b;
3.8 Bitwise Operator
C has a distinction of supporting special operators known as bitwise operators for manipulation of data at bit level. These operators are used for testing the bits, or shifting them right or left. Bitwise operators may not applied to float or double. Operator & | ^ << >> Meaning bitwise AND bitwise OR bitwise exclusive OR shift left shift right
Example 3.2
The Program prints a sequence of squares of numbers. Note the use of the shorthand operator *=. #define N 100 #define A 2 Output main() 2 { 4 int a; 16 a = A; while(a<N) { printf(“Enter days\n”); a *= a; } }
Introduction to Computer (C Programming)
Chapter3 Operators and Expressions
Software College , Northeastern University 2007,9
3.1 introduction
C operators can be classified into a number of categories. They include:
3.6 Increment and Decrement Operators
C has a set of ‘shorthand’ operators of the form: v op =exp; where v is a variable, exp is an expression op is a C binary arithmetic operator op= is known as the shorthand assignment operator v op =exp; is equivalent to v =v op (exp);
3.9 Special Operators
Pointer Operators: & and * Member Selection Operators: . and ->
The Comma Operator: can be used to link the related expression together. A comma-linked list of expressions are commaevaluated left to right and the value of right-most rightexpression is the value of the combined expression.
1. 2. 3. 4. 5. 6. 7. 8. Arithmetic operators. Relational operators. Logical operators. Assignment operators. Increment and decrement operators. Conditional operators. Bitwise operators. Special operators.
Op_1
Non_zero Non_zero 0 0
Op_2
Non_zero 0 Non_zero 0
Value of the Expression op_1&&op_2 op_1||op_2
1 1 1 1 1 1 1 1
Examples:
1. if (age > 55 && salary < 1000) 2. if (number < 0 || number > 1000)
The use of shorthand assignment operators has three advantages:
1. 2. 3. What appears on the left-hand side need not be repeated leftand therefore it becomes easier to write. The statement is more concise and easier to read The statement is more efficient
3.3 Relational Operators
C supports six relational operators in all: Operators Meaning
< <= > >= to == != is equal to is not equal to is less than is less than or equal to is greater than is greater than or equal
Example
4.5<=10 10<7+5 4.5<4.5<-10 a+b=c+d ? -35>=0
Relational Operator Complements
Among the six relational operators, each one is a complement of another operator. > is complement of <= < is complement of >= == is complement of != We can simplify an expression involving the not and the less than operators using the complements as shown below: Actual one Simplified one !(x<y) x>=y !(x>y) x<=y !(x!=y) x==y !(x<=y) x>y !(x>=y) x<y !(x==y) x!=y
3.2 Arithmetic operators
Operator
+ - * / %
Meaning
Addition or unary plus Subtraction or unary minus Multiplication Division Modulo division
Examples:
a-b, a+b, a*b, a/b, a%b
3.4 Logical Operators
C has the following three logical operators:
&& || ! meaning logical meaning logical meaning logical AND OR NOT
Example:
Truth Table
Examples: x+=y+1; x+=3; is equivalent to is equivalent to x=x+(y+1); x=x+3;
Shorthand Assignment Operators
Statement with simple assignment operator a=a+1 a=a–1 a = a * (n+1) a = a / (n+1) a=a%b Statement with shorthand operator a += 1 a -= 1 a *= n+1 a /= n+1 a %= b
– Example: value = (x = 10, y = 5, x + y); – value = 15; – Some applications of comma operator are: In for loops: for ( n = 1, m = 10, n <= m; n++, m++ ) In while loops: while( c = getchar( ), c != ‘10’ ) Exchanging values: t = x, x = y, y = t;
Example 3.1
The Program shows the use of integer arithmetic to convert a given number of days into months and days.
main() Output { int months, days; Enter days 265 printf(“Enter days\n”); Months=8 Days=25 scanf(“%d”, &days); Enter days months = days/30; 364 days = days % 30; Months=12 Days=4 printf(“Months=%d Enter days months, days); days=%d”, 45 } Months=1 Days=15
– a = 10; b = 15; x = (a > b) ? a : b; – if (a > b) x = a; else x = b;
3.8 Bitwise Operator
C has a distinction of supporting special operators known as bitwise operators for manipulation of data at bit level. These operators are used for testing the bits, or shifting them right or left. Bitwise operators may not applied to float or double. Operator & | ^ << >> Meaning bitwise AND bitwise OR bitwise exclusive OR shift left shift right
Example 3.2
The Program prints a sequence of squares of numbers. Note the use of the shorthand operator *=. #define N 100 #define A 2 Output main() 2 { 4 int a; 16 a = A; while(a<N) { printf(“Enter days\n”); a *= a; } }
Introduction to Computer (C Programming)
Chapter3 Operators and Expressions
Software College , Northeastern University 2007,9
3.1 introduction
C operators can be classified into a number of categories. They include:
3.6 Increment and Decrement Operators
合集下载
C语言英文课件2:数据类型
perimeter and the area */
}
Result: r =1.500000 l = 9.42, s= 7.07
4. DECLARATION AND INITIALIZATION
(1) DECLARATION form:
< data type> < variable name >[,< variable name2>……];
•Data is the object be processed by algorithm
•Data types in C:
integer 1.Basic Types
real(float) character enum array 2. Tectonic Types structure union 3. Pointer 4.NULL
(1) VARIABLE NAME:keep to rules for identifier
(2) MEMORY UNIT
(3) VALUE
Nonce value
In a program,we can quote variable by variable names
p
variable name
3
location
2. Sort
CONSTANTS
symbolic CONSTANTS
can be differentiated by writing format
2.3.2 VARIABLES
1. Concept
Its value can be changed during program
executing
2. Three elements of variables
C语言基础教程课件(英文版)ch11
– grade = &grade[2]; is invalid
•
A pointer access can always be replaced using subscript notation
– numPtr[i] is valid even if numPtr is a pointer variable
16
Pointer Arithmetic (continued)
A First Book of ANSI C, Fourth Edition
17
Pointer Arithmetic (continued)
Can be replaced with total += *nPtr++
A First Book of ANSI C, Fourth Edition
A First Book of ANSI C, Fourth Edition
29
Processing Strings Using Pointers
void strcopy(char string1[], char string2[]) { int i = 0; while (string1[i] = string2[i]) i++; } void strcopy(char *string1, char *string2) { while (*string1 = *string2) { while (*string1++ = *string2++) ; string1++; string2++; } return; }
A First Book of ANSI C, Fourth Edition
•
A pointer access can always be replaced using subscript notation
– numPtr[i] is valid even if numPtr is a pointer variable
16
Pointer Arithmetic (continued)
A First Book of ANSI C, Fourth Edition
17
Pointer Arithmetic (continued)
Can be replaced with total += *nPtr++
A First Book of ANSI C, Fourth Edition
A First Book of ANSI C, Fourth Edition
29
Processing Strings Using Pointers
void strcopy(char string1[], char string2[]) { int i = 0; while (string1[i] = string2[i]) i++; } void strcopy(char *string1, char *string2) { while (*string1 = *string2) { while (*string1++ = *string2++) ; string1++; string2++; } return; }
A First Book of ANSI C, Fourth Edition
C语言英文完整Chapter 10PPT课件
(1) struct student
{ int num; char name[20]; …… float score2;
} stu1, stu2;
(2) struct
{ int num; char name[20]; …… float score2;
} stu1, stu2;
3、demonstration (1)differ structure type and variable,which are
};
struct student { int num; char name[20]; char sex; int age; float score1; float score2; };
精选PPT课件
3
demonstration:
1、the rules to name“structure type name”and “member name” ,are same with the variables’.
num name sex age score1 score2
stu1
1、indirect declaration
──first declare the structure type,then the
structure variables
struct student
{ int num; char name[20];
10.1 structure definition 10.2 structure variables citing and initialization
10.3 structure array
10.4 structure pointer
10.5 link dispoing--- application of structure pointer
C语言英文课件Chapter10PPT教学课件
[eg10.1] creat a structure reffering to basic information of a student to store the details of a student
struct date /*data structure type made of year,month and day*/
STUDENT SCORES MANAGE TABLE
num 1001 1002 1003 1004
name sex age score1 score2
Zhang Xin M 20
87
91
Wang Li F 20
98
96
Chen Fong M 21
86
90
Li Xiaopen M 20
77
86
DIFFERENT TYEPES!
3
demonstration:
1、the rules to name“structure type name”and “member name” ,are same with the variables’.
2、the definitions of variables can be seperated or in a same line like the instance below
2020/12/10
CANOT DEAL WITH 2D ARR2AYS源自truct student num
name
sex age score1 score2
二、 structure type declaration Common usage: Type name
struct structure typename
C语言基础教程课件(英文版)ch13
– Last-in, first-out (LIFO) list
• In a true stack, the only item that can be seen and accessed is the top item
A First Book of ANSI C, Fourth Edition
19
A First Book of ANSI C, Fourth Edition
10
Introduction to Linked Lists (continued)
is evaluated as (t1.nextaddr)->name it can be replaced by (*t1.nextaddr).name
– Also known as self-referencing structures
A First Book of ANSI C, Fourth Edition
4
Introduction to Linked Lists (continued)
A First Book of ANSI C, Fourth Edition
A First Book of ANSI C, Fourth Edition 22
PUSH and POP (continued)
A First Book of ANSI C, Fourth Edition
23
PUSH and POP (continued)
A First Book of ANSI C, Fourth Edition
13
Introduction to Linked Lists (continued)
can be replaced by while(!contents)
• In a true stack, the only item that can be seen and accessed is the top item
A First Book of ANSI C, Fourth Edition
19
A First Book of ANSI C, Fourth Edition
10
Introduction to Linked Lists (continued)
is evaluated as (t1.nextaddr)->name it can be replaced by (*t1.nextaddr).name
– Also known as self-referencing structures
A First Book of ANSI C, Fourth Edition
4
Introduction to Linked Lists (continued)
A First Book of ANSI C, Fourth Edition
A First Book of ANSI C, Fourth Edition 22
PUSH and POP (continued)
A First Book of ANSI C, Fourth Edition
23
PUSH and POP (continued)
A First Book of ANSI C, Fourth Edition
13
Introduction to Linked Lists (continued)
can be replaced by while(!contents)
C语言英文版课件
C Language Programming
Zhang Xiaohang
张晓航 zhxiaohang@
C Language Programming
2
Class
12B07 12B08 12B09 12B10
Theory (place & time)
教二楼326 13:30~15:20 Monday
– Electronic components – Human operator manipulated external wiring
• Electrical Numerical Integrator and Computer (ENIAC, 1946)
– 18,000 Vacuum tubes – Weighted 30 tons / 5000 additions or 360 multiplications
Textbook: A First Book of ANSI C Fourth Edition
Grade is determined by –Experiment 10%
–Middle exam 15%
–Course work 5% –Final exam 70%
Website: /CPF
• The collections of patterns consisting of 0s and 1s used to represent letters, single digits, and other single characters are called character codes(字符编码)
• Mark I (1944)
– Mechanical relay switches
• Electronic Delayed Storage Automatic Computer (EDSAC, 1949)
Zhang Xiaohang
张晓航 zhxiaohang@
C Language Programming
2
Class
12B07 12B08 12B09 12B10
Theory (place & time)
教二楼326 13:30~15:20 Monday
– Electronic components – Human operator manipulated external wiring
• Electrical Numerical Integrator and Computer (ENIAC, 1946)
– 18,000 Vacuum tubes – Weighted 30 tons / 5000 additions or 360 multiplications
Textbook: A First Book of ANSI C Fourth Edition
Grade is determined by –Experiment 10%
–Middle exam 15%
–Course work 5% –Final exam 70%
Website: /CPF
• The collections of patterns consisting of 0s and 1s used to represent letters, single digits, and other single characters are called character codes(字符编码)
• Mark I (1944)
– Mechanical relay switches
• Electronic Delayed Storage Automatic Computer (EDSAC, 1949)
--C语言程序设计课件PPT(英文)C program language 之4 Control flows
Condition
Test the condition , when the result is true, execute A , otherwise ,execute B
Repeat some statements.
When condition is true, repeat A, stop while false
LOGO
Chapter Four Control flows
Contents
1 Basic control flows in C 2 If statement 3 Switch statement 4 Loop structure 5 Break and continue statements 6 goto and labels
The if –else statement is used to express decisions. Formally the syntax is:
if(expression) Where the else part is optional.The
statement1 expression is evaluated ; if it is true,
}
If statement
2 nesting - if statement if(exp) if ( exp1) else else if (exp2) else
statement11 statement12 statement21 statement22
Y
Y
N
exp1
exp
N
Y
N
exp2
statement11 statement12 statement21
C语言基础教程课件(英文版)ch15
A First Book of ANSI C, Fourth Edition
5
Procedural Programming in C++ (continued)
Equivalent to C’s newline sequence '\n' (which is also available in C++) followed by a flush() function call
A First Book of ANSI C, Fourth Edition 16
Summary (continued)
• Inheritance is the ability to create a new class by extending the definition of an existing class • Polymorphism is the ability to have the same function perform different tasks depending on the class it is a member of • Every variable in a C++ program must be declared as to the type of value it can store
• Polymorphism permits the same operation to invoke one set of results on data values of a base class and a different set of results on data values of a derived class • Using polymorphism, existing operations on a base class can be left alone, without the need to retest and reverify them, while they are extended to a derived class
C语言双语教学c双语[1reface]PPT课件
– C compilers and C programs run on all sorts of computers
– Unix happens to be written in C.
2020/11/23
E-mail:
12
32 keywords:defined and used by C
Characteristics
C语言特点
The simplest C program C程序格式和结构特点
How to run C program C程序上机步骤
2020/11/23
E-mail:
6
1.1 C’s background
程序设计是数据被加工的过程
High level lang
Assemble lag
2020/11/23
E-mail:
9
◆ Let’s trace the development
Algol60 (1960)
2020/11/23
CPL (1963) BCPL (1967)
B (1970)
C (1972)
E-mail:
where:
Bell lab aim:
UNIX OS designer:
Problem-oriented languages(Fortran, Pascal) C
Machine-oriented languages(BCPL,B,)
Assembly languages
Hardware
2020/11/23
E-mail:
8
◆ The origin of C language
5 Arrays and Pointers
国外C语言程序设计英文-lecture3 ppt课件
• Simple example: displaying a message 100 times:
printf(“hello !\n”); printf(“hello !\n”); printf(“hello !\n”);
… printf(“hello !\n”); printf(“hello !\n”);
Repeat 100 times printf(“hello !\n”);
Program looping: enables you to develop concise programs containing
repetitive processes that could otheprpwt课ise件require many lines of code !
int triangularNumber; triangularNumber = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8; printf ("The eighth triangular number is %i\n",
triangularNumber); return 0; }
What if we have to compute the 200-th (1000-th, etc) triangular number ?
– Program Input
– for Loop Variants
– The while Statement
– The do Statement
– The break Statement
– The continue Staptpet课m件 ent
2
Executing a program
