C language programming-operators and expressions

Operators and expressions
Expressions are composed of operators and operands.
Expressions can be generated in the following two situations:
1. Placed on the right side of the assignment statement
2. Placed in the function parameters.
The return value of each expression has Use of logical
expression values

#include <stdio.h>
int main(int argc, char const *argv[])
{
    
    
 ine a,b,v;
 int a=1;
 int b=2;
 int c=3;
 printf("the frist number is:%d\n",a );
 printf("the second number is:%d\n",b );
  return 0;
}

Operation properties
Assignment operator
Arithmetic operator
Increase and decrease 1: When
used as a prefix operator:
++ n --n;
m=++n:/*n=n+1
m=nb
*/When
used as a postfix operator :
N++ n–:
m=n++:/*m=n
n=n+1
*/
Type forced conversion
Relational operator
Logical operator
Bit operator
operand Operand
object (constant, variable, function)
Automatic type conversion:
Numerical overflow :
Overflow:
|A numerical operation structure|>|The maximum number that a type can represent|The
carry exceeds the highest position and the carry is lost,
or the carry reaches the highest position and the sign bit changes
the operation results of different types of data. The value range is larger Type
All operands are converted to the type of the operand with a larger value range.
Numerical precision loss:
In the process of forced conversion of different types of data, the accuracy of a small range of data types is converted into a large range of data types.
printf(); Format character
%d output decimal signed int type
%u output decimal unsigned int type
%f output float, double type in decimal form (6 decimal places)
%e output float in standard exponential form, double type
%c output a single character in character form
l plus d, output long before u,
h plus d, output short before u
, the smallest domain width occupied by the data
ASCLL code can be uppercase and lowercase English The ASCLL code value of the letter differs by 32
single-character input and output:
putchar(a) / output a character like a screen, the value of the character variable a /
character input function getchar()
a =getchar() / character accepted from the keyboard as getchar Function value of ()
No parameter
/

/*大写英文字母转换成小写英文字母*/
#include <stdio.h>
int main(int argc, char const *argv[])
{
    
    
 char a;
 putchar("请输入您的英文字母");
 a=getchar();
 a=a+32;
 putchar(a);
 putchar('\n');
 return 0;
 }
/*输入三个数据类型 整型  字符型  浮点*/
#include <stdio.h>
int main(){
    
    
 int a;
 char b;
 float c;
 
printf("Please input an  integer :" );
 scanf("%d",&a);
 printf("integer:%d\n",a );
 
printf("Please input a  charreacter:");
 scanf(" %c",&b);
 printf("%c\n",b );
 
printf("Please input a float number:" );
 scanf("%f",&c);
 printf("%f\n",c );
 return 0;
}

Relational Operators and Logical Operators
Relational Operators
Arithmetic Operator -> Relational Operator (true (1) false (0))

<
<=

=
Higher than the last two priorities
==
!=

/*例子*/
#include <stdio.h>
int main(){
    
    
 int a,b,c;
 a=1;
 b=2;
 c=3;
 printf("%d\n",a>b>c ); 
 /*
                                 a>b>c我们可以看作(a>b)>c
                                 (a>b)=3>2,为真,所以a>b的值为1
                                   带入(a>b)>c中,得出1>1,
                                   所以a>b>c的假=0
                             */
  return 0;
}

Logical operators and logical expressions
&& logical AND
|| logical OR
! Logical negation Logical
negation-
the short-circuit characteristic of the right combined logical operator:
if the value of the expression can be derived from the value of the left operand calculated first, then the value of the right operand will no longer be calculated.
Conditional expression:
expression 1 ? Expression 2: Expression 3
/ If the value of expression 1 is true, then the value of expression 2 is assigned to the entire conditional expression, if the value of expression 1 is false,
then the value of expression 3 is assigned to the entire Conditional expression
/

/*列子;求两个数的最大值*/
#include <stdio.h>
int main(){
    
    
 int a ;
 int b;
 printf("Input  a,b");
 scanf("%d %d",&a,&b);
 printf("max=%d\n",a>b ? a:b); 
 return 0;
 }

Guess you like

Origin blog.csdn.net/weixin_45743004/article/details/103812333