当前位置:网站首页>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 !
边栏推荐
- Large number operation (capable of square root, power, permutation and combination, logarithm and trigonometric value)
- Mysql interactive_ Timeout and wait_ Timeout differences
- Difference between asemi high power FET and triode
- How to install the blue lake plug-in to support Photoshop CC 2017
- Page electronic clock (use js to dynamically obtain time display)
- A summary of the experiment of continue and break in C language
- Teach you to write non maintainable PHP code step by step
- How micro engine uploads remote attachments
- [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
- Detailed summary of float
猜你喜欢

Use serialize in egg to read and write split tables

SSRF-lab

XSS (cross site script attack) summary (II)
![H5 canvas drawing circle drawing fillet [detailed explanation]](/img/6f/a33a323b6cd0918066e8b71a22d841.jpg)
H5 canvas drawing circle drawing fillet [detailed explanation]

Use js to simply implement the apply, call and bind methods

Enhanced paste quill editor

Attack and defense world web baby Web

Essais de pénétration - sujets d'autorisation

JSON Library Tutorial from scratch (II): parsing digital learning and sorting notes

Ranorex Studio 10.1 Crack
随机推荐
Customize the console plot result style
Difference between asemi high power FET and triode
Example of dynamic programming 3 leetcode 55
CUDA compilation error
Object creation and invocation code example
MySQL prevents Chinese garbled code and solves the problem of Chinese garbled code
Stack and Queue
滲透測試-提權專題
Eyeshot Ultimate 2022 Crack By Xacker
There is 404 in the laravel visit, except the home page is redirected; Index php
Mobile number regular expression input box loses focus verification
Basic bit operation symbols of C language
Summary of SQL injection (I)
Vue uses keep alive to cache page optimization projects
What if win11 Bluetooth fails to connect? Solution of win11 Bluetooth unable to connect
Electronic Society C language level 1 28, character diamond
Two hours to take you into the software testing industry (with a full set of software testing learning routes)
DOM document object model (I)
Route parameters to jump to the page and transfer parameters -- > hidden parameter list
Creation and use of MySQL index