[C language - first understanding of C language (3)]

C language basic preparation


foreword

Continuing from the previous article, the content of this article is still the preparatory knowledge of the basic content of the C language.

10. Operators

This is only a brief introduction, and I have an initial impression of all operators.

insert image description here
insert image description here
insert image description here
Exercise 1:

int main()
{
    
    
	//C语言中,0表示假,非0表示真
	int flag = 5;//非0为真,1是真,2也是真
	if (!flag)//!flag为1才能进入if条件语句,打印hehe
	{
    
    //此时flag为假,即为0才行
		printf("hehe\n");
	}
	int a = -10;//a = a - 10;
	int b = +a;//b=a+b;
	printf("%d\n", b);

	int a = 10;
	printf("%d\n", sizeof(a));//单位是字节
	printf("%d\n", sizeof(int));


	int a = 1;
	int b = a + 1;
	int b1 = ++a;//前置++,先++,后使用//a = a+1; 然后执行b=a;
	int b2 = a++;//后置++,先使用,后++ //int b = a;然后a=a+1;
	
	int b = --a;//a=a-1;b=a;
	int b = a--;//b=a;a=a-1

	printf("a=%d b=%d\n", a, b);//9 10

	int a = 1;
	//int b = (++a) + (++a) + (++a);//错误的代码
	printf("%d\n", b);

	return 0;
}

Exercise 2:

int main()
{
    
    
	int a = (int)3.14;//强制转换

	printf("%d\n", a);

	return 0;
}

Exercise 3:

int main()
{
    
    
	int a = 10;
	if (a>=10)
	{
    
    
		printf("hehhe\n");
	}
	return 0;
}

Exercise 4:

int main()
{
    
    
	int a = 10;
	if (a = 10) //a=10是将10赋值给a,a为10,非0,则为真
	{
    
    //满足条件,执行打印操作
		printf("hehhe\n");
	}
	return 0;
}

Exercise 5:

int main()
{
    
    
	int a = 10;a=10是将10赋值给a
	if (a == 5) //a为10,不等于5,为0,则为假
	{
    
    //不满足条件,不执行打印操作
		printf("hehhe\n");
	}
	return 0;
}

Exercise 6:

int main()
{
    
    
	int a = 5;
	int b = 5;
	if ((a==3)||(b==5))
	{
    
    
		printf("hehh\n");
	}
	if ((a == 3) && (b == 5))
	{
    
    
		printf("hehh\n");
	}
	return 0;
}

Exercise 7:

int main()
{
    
    
	int arr[10] = {
    
     0 };
	arr[5] = 9;
	return 0;
}

Summarize

The content of this article is relatively small, only a brief introduction to operators is included.

Guess you like

Origin blog.csdn.net/taibudong1991/article/details/123713086