c语言中的几种运算符

 

001、相等运算符

==

!=

 

002、关系运算符

>

>=

<

<=

 

003、条件运算符

a ? b:c

[root@localhost test]# ls
test.c
[root@localhost test]# cat test.c
#include <stdio.h>

int main(void)
{
        int n1,n2;

        puts("please input two integers.");
        printf("n1 = "); scanf("%d", &n1);
        printf("n2 = "); scanf("%d", &n2);

        int max;
        max = (n1 > n2) ? n1:n2;

        printf("max is %d\n", max);

        return 0;
}
[root@localhost test]# gcc test.c -o kk
[root@localhost test]# ls
kk  test.c
[root@localhost test]# ./kk
please input two integers.
n1 = 8
n2 = 3
max is 8
[root@localhost test]# ./kk
please input two integers.
n1 = 2
n2 = 7
max is 7

 .

 

004、逻辑非运算符

!.

 

 

 

 

 

 

 

 

.

posted @ 2024-09-04 09:12  小鲨鱼2018  阅读(25)  评论(0)    收藏  举报