当前位置:网站首页>First knowledge of C language - why does every C program have a main function
First knowledge of C language - why does every C program have a main function
2022-07-27 05:37:00 【yin_ Yin】
We're writing C When you program, you will find that every program has one main function , Why is that ? every last C Are all procedures necessary ?
The answer is : Yes !!!
main function , Also called principal function , Is the starting point of program execution ,main Relatively speaking , Just as the tone of phonology theory is overtone , Overtone is division in program main Other functions besides , A pattern that caters to people's way of thinking rather than necessarily . There are masters and there are times , The implementation is clear , It can modularize the program and realize a closed whole .
In any one C In the program ,main Functions are essential ,main Function is the only entry of the program , in other words , Program runtime , First of all, from the main The function starts executing .
Look at this code :
#include <stdio.h>
int main()
{
int n = 0;
int count = 0;
scanf("%d", &n);
if (n < 12)
count = 2;
else
count = n / 12 * 4 + 2;
printf("%d\n", count);
return 0;
}

3. At the same time, we should pay attention to one C The program must have and can only have one main function , If there are more than one in a program main function , Then something must go wrong .
#include <stdio.h>
int main()
{
return 0;
}
int main()
{
int a = 0;
printf("%d\n", a);
return 0;
}

边栏推荐
猜你喜欢

p7 day1 初识Flask框架

Li Hongyi machine learning team learning punch in activity day06 --- convolutional neural network

Hi3516dv300 environment setup

用户的管理-限制

分享力扣—189.轮转数组 的三种解法

pytorch安装新坑

初识C语言——常见的数据类型

Li Hongyi machine learning team learning punch in activity day03 --- error and gradient decline

初识C语言——什么是C语言

Carmaker quick start lesson 4 developing 48V P1 hybrid system
随机推荐
Dnsmasq Usage Summary
初识C语言——初识指针
页面布局中元素定位的几种方式
后台实现sku 管理
Redis transaction
Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)
Makefile 通俗易懂详解
flask一对多数据库创建,基础增删改查
Flask的传参以及返回的响应
后台订单管理
分享一道关于程序编译过程的选择题(内含编译过程浅谈,符号表的形成合并过程)
用户登录-以及创建、验证短信验证码
用pygame自己动手做一款游戏01
C language string introduction and related operation functions
arguments
我的第一篇博客
JS中是如何使用for..of来遍历对象
SQL database → constraint → design → multi table query → transaction
JS中forEach和map方法有什么区别
Flask的使用