当前位置:网站首页>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 !
边栏推荐
- Go Methods and Interfaces
- Vue uses keep alive to cache page optimization projects
- Enhanced paste quill editor
- The article is on the list. Welcome to learn
- Customize the console plot result style
- Summary of SQL injection (I)
- Makefile Foundation
- The construction and usage of wampserver framework
- Qdebug June 2022
- Precise delay based on Cortex-M3 and M4 (systick delay of system timer can be used for STM32, aducm4050, etc.)
猜你喜欢

PHP calls map API

Deeply understand the characteristics of standard flow and off standard elements

Extend the toolbar of quill editor

C language -- Sanzi chess

2022.1.23 diary

What is Ethernet and how to connect the computer

What if win11 Bluetooth fails to connect? Solution of win11 Bluetooth unable to connect

Install pytorch through pip to solve the problem that torch cannot be used in jupyter notebook (modulenotfoundererror:no module named 'Torch').

How to open the DWG file of the computer

Use js to simply implement the apply, call and bind methods
随机推荐
Ranorex Studio 10.1 Crack
Difference between asemi high power FET and triode
2022.1.21 diary
C language - minesweeping
For in JS Of and for in
Route parameters to jump to the page and transfer parameters -- > hidden parameter list
Try block and exception handling
Penetration information collection steps (simplified version)
Basic knowledge of web pages (URL related)
Charles and iPhone capture
Dynamic programming example 2 leetcode62 unique paths
Jason learning
Tanhaoqiang C language practice
Japanese fifty tone diagram
Professional things use professional people
Reading and writing of nodejs excel (.Xlsx) files
ORA-00800: soft external error
Create an environment for new projects
Edge loss interpretation
HR took the initiative to raise the salary of the test lady. How did she do it?