当前位置:网站首页>I got to know data types and function variables for the first time. I learned data types and function variables together today and yesterday, so I saved them in the first issue to record.
I got to know data types and function variables for the first time. I learned data types and function variables together today and yesterday, so I saved them in the first issue to record.
2022-06-25 05:21:00 【108 rings 02】
First of all, data type is the type of data as the name suggests , There are many data types in life , Like constants , It's like age , And some big numbers , Like a number used to record astronomical numbers , And weight , How many kilos is it accurate to ? Keep one place after the decimal point , So we learn C How should the language define these numbers ? Here are some C Data types commonly used in language and methods of using data types .

It is noted that char Different from other types , It represents the character type , So separate them , The method is to use single quotation marks to enclose the characters we want to enter , Put it in a space , The choice here is ch, As for why ch It's because of habit , He can be any name ( Personal test , I am using fh Tried it on ),int For integer , Other short The formal writing is short int, however short If the grammar is OK, you can write it like this .
Here we also need to pay attention to the point that we are using printf Function outputs our int Represents an integer variable , Our grammar is "%d\n", there %d It means to allow an integer , especially int Number defined , Allied , We also have
Allied , We also have float, Single precision floating point and double, Double precision floating point . In use respectively printf When using the function %f and %lf To express float and double.

Here is a special introduction sizeof() Function usage ,sizeof Is a calculation type or the size of the occupied space , It can be used to calculate the size of the operational storage space of the data type we want to know .
![]()
For example, we are shown in the figure , We have used... Separately sizeof Function calculates the space occupied by the different data types we just learned , The unit is bit, The bit .

We can see char The space occupied is 1 The bit , And so on .
After introducing our data types , Let's talk about variables , What are variables , For example, the salary in our life is a variable , Our salary will change , So we have to use C The method of language to systematically specify . Here we introduce global variables and local variables , How to distinguish between global variables and local variables , In fact, the methods are easy to distinguish , The method is to put curly braces {} All variables defined in are local variables , In braces {} The variables defined outside are global variables .

Like this , In braces {} Outside is the global variable , In braces {} Inside are local variables . So you know why I define it here at the same time a Value , The answer is 10, instead of 100 Well ?
The reason is that when the names of local variables and global variables conflict , Local priority , It is clear here that we define a When the value , Global and local variables conflict , So local variables take precedence , So the local variables are output 10.
So when we write programs , Try not to define global variables and local variables as the same letter .
Finally, here we are introducing a new function , Output input function scanf, This function allows us to enter what we want into the letters we define , Its syntax format is as follows , stay %d Followed by & The symbol refers to what we are going to input .

For example, we design a code to find the sum of two integers

It's OK to write like this , Give variables initial values at the beginning 0, Later on scanf Function to let us input the value we want , however

The system will report an error , The reason is because scanf Function is not safe enough , It is recommended that we do not use scanf function , Here we use vs My friend can be changed to scanf-s To become a safe function , however scanf-s yes vs A small program compiled by the software itself , Not applicable to other compiler software , The solution is , Put the symbols in the output on the first line of all functions as shown in the figure , Run the program again , This is the standard C Solve in language scanf Function unsafe methods .

We write this safe method that it prompts us on the first line of the program , In this way, it can be used safely

But there are more convenient ways , We found in our computer newc++file The file of , Remember his path

Then we open our Notepad , Run as Administrator

We click Open... In the file in Notepad

Later, we will copy and paste the path we recorded before

We enter this in Notepad

After that, we will create a new project with source files

We can see that this line of code already exists at the beginning of the file when we just put on the file , It will be convenient for me in the future , We can safely and boldly use scanf Function !

This is the end of this period , But I am in the attitude of solving problems , I want to know why scanf Functions are not safe , Because scanf The function itself has bug, And others can take advantage of scanf Of this function bug To modify the program ? Based on this problem, I go online to check the information , It turns out that this is the case , As I thought .

Today's learning is shared here , See you next time !
边栏推荐
- A summary of the experiment of continue and break in C language
- Create dynamic array
- Flex flexible layout for mobile terminal page production
- What is Ethernet and how to connect the computer
- Database low-end SQL query statement fragment
- Everything is an object
- Edge loss interpretation
- H5 canvas drawing circle drawing fillet [detailed explanation]
- 2021-04-02
- TX Text Control 30.0 ActiveX
猜你喜欢

Specific operations for uploading pictures in PHP

Create an environment for new projects

Extend the toolbar of quill editor

CTFHUB SSRF

Laravel's little knowledge

Svg code snippet of loading animation

February 20ctf record

API interface management setup -eolinker4.0

What is Ethernet and how to connect the computer

How to install the blue lake plug-in to support Photoshop CC 2017
随机推荐
Database overview
Prototypical Networks for Few-shot Learning
Bind simulation, key points of interpreting bind handwritten code [details]
JSON Library Tutorial from scratch (III): parsing strings, learning and sorting notes
JSON Library Tutorial from scratch (II): parsing digital learning and sorting notes
滲透測試-提權專題
H5 canvas drawing circle drawing fillet [detailed explanation]
How to make colleagues under the same LAN connect to their own MySQL database
Duplicate symbols for architecture i386 clang
[Huawei machine test] hj16 shopping list
Eyeshot 2022 Released
[relax's law of life lying on the square] those poisonous chicken soup that seem to be too light and too heavy, but think carefully and fear
Two hours to take you into the software testing industry (with a full set of software testing learning routes)
Reading and writing of nodejs excel (.Xlsx) files
TX Text Control 30.0 ActiveX
SRC platform summary
How to download and use Xiaobai one click reload on the official website
Database query optimization method
Go deep into the working principle of browser and JS engine (V8 engine as an example)
Jason learning