First contact with computer programming language--c language
After admission to the introduction of computer after the edification, in the second half of the freshman semester I finally came into contact with a language, which is our first contact with the computer programming language--c language.
In the beginner's time, the feeling of this course is very obscure, but when the study for a period of time, then found that in fact, it is only so. As the saying goes, language is the carrier of thought, yes, we human have our communication language, animals have their own unique language, the computer also has the means of communication, also need to communicate, this is what I think C language, so C began to enlighten me. Here I would like to talk about my course of study and my own views on the language, because the author's ability is limited, there must be some shortcomings, but also ask friends to forgive, please correct me.
C language development, I don't have to say, compared to the well-known, I simply say I think. Because people are willing to communicate with the strong desire of computer, so contact computer hardware and software machine language appeared, but too cumbersome, so the development continues to develop, with C language, C language has become very popular, so we all in use, with every place in the evolution of different C language, Even if the language of our country, speaking is Chinese, but each place to him covered with a layer of local characteristics, dialects are everywhere, so someone wants to standardize the language, like Mandarin, unified the C language version, so that everyone better understand it.
&NBSP;C language has many advantages, here I do not enumerate, this my first familiar language also let me love it. I have been exposed to a lot of code in the study, and then I know that in fact most of what I learned is pseudo-code, but for the convenience of learning, can be. C language just learning, I feel like when working, first you need tools, this tool? Must be found in the toolbox, so you need to say, "I want to use tools", so as to obtain the use of tools. The tool is the header file, the Toolbox has a lot of tools we need, just get started we just need this "<stdio.h>" a tool, you want to use the tool, so you want to declare, so you need to "#include" command to reference your "tool", It's like taking a tool out of the toolbox. If you're going to build a thing, you need a big container package, and it has to be unique, so the legendary main () function appears, don't get excited, the main () function is really just the need for C language operation, called the main function, everyone has a torso, The C language of the trunk is the main () function, and "torso" can only have one bar, then the light has a torso is not ah, no real goods, or hollow, useless. So you need something to fill your torso and make him useful. C language is the key that you open the door of computer world, this is you want to say hello to C language, that use C language output, this is what we want to fill, you need to "express", is printf, put you need to say the words in quotation marks, say finished words must have end, in C with ";" to replace. "So, C language to you said the first sentence so out, black and black console appeared C language greeting, that feeling is not very good."
#include <stdio.h> Main () { printf ("Hello,world!") ; } |
In mathematics we have variables, there are variables in C, but this variable is more powerful and can help us do more things. There are integers, fractions, decimals in mathematics for numbers ... In the C language, we can also have these numbers, math we do the topic will say this variable x what number, in C, we also need, just, C has the C expression, this is the data type, int is the integer type, float type with float, double to represent, you think right, Float is the type of decimal point, but the latter can express more than the valid number, so you can "double". In the C language, can also be like math, but the operation symbol expression slightly different, + 、-、 *,/, are very simple, but about the equal sign, in C is required two equals "= =", this is particularly necessary for beginners to note, you may recall this is why, because a "=" number has other meanings, So we can only use two. So we say this one "=", an equal sign is assigned, that is, what value to the variable, such as X = 10 (in C, if you do not assign a variable, C will automatically give it a default value of 0) This is not X equals 10, this in C is the 10 value, to the x this variable, is not very much to subvert your values, in fact, there are more subversive, haha, open a joke, this is the C language norms, you are talking to the computer, of course, you can not press their own, you have to press the computer's walk. Just to mention that in C, variables are declared and reused, which is what you say is the type of the variable. There is also a percent, this is not a percent, I think you are also accustomed to, this is the operator of redundancy, is to find the remainder of a number. You want to do an operation, then define an integer (int) variable sum, and then define two integer variables x, y, the value of 2 to the variable x, 3 to Y, the value of the x+y to sum, in C, to the right to the left to write, only the C language can understand, and finally the value of the sum of output is good, Output also need type, that is in printf with "%d" for integer variables, the real type of the%f is good, because you want to tell C, you want to print the sum of the value, so you have to write the sum, you also need to use "," to separate, so you can already use C language to do the operation, See if you can print out 5?
#include <stdio.h> Main () { int sum; int X=2,int y=3; sum = x + y; printf ("%d", sum); } |
After the demonstration of the above two examples, I believe you have a general feeling about C language. Let's say a sequential structure program. The C language is divided into five statements, 1, expression statements, such as X=Y+Z;2, function call statements, such as printf ("%d", x) \scanf ("%d", X), 3, control statement 4, compound statement, 5, empty statement. Let us say a few words about the choice structure. The program that we use cannot always go down a path, and in many cases there will be branches, so if the statement acts as a function, if (expression) statement, if the value of the expression is true, the statement after execution, or not execute the statement, generally do not often encounter two branches, more than a branch? Using the Else statement, else is used in conjunction with if, and multi-branching is implemented in multiple if-ele-if forms. The switch statement supports jumping, which case needs to be executed.
While loop, first judge, then execute the loop statement, Do-while Loop, first execute the loop body, in the judging condition, the For loop function is strongest, so it is also more complex for (expression 1; expression 2; expression 3), the step is to solve the expression 1, in the solution Expression 2, if the result is true, Executes expression 3 After the statement is executed, otherwise executes the next statement. The For statement is best used when the number of loops is determined. With these three loops, the for loop can replace the other two loops, so there are more opportunities for the For loop.
When you want to perform multiple loops, but want to skip a step, the break statement jumps out of the loop, and the continue statement ends the loop.
Sometimes when you define a lot of variables, and they are of the same type, you will want to put the same class together to manage, then the function of the array is highlighted. The collection of these ordered, homogeneous data elements is called an array. The general form of a one-dimensional array: the array name [subscript], the subscript can only be an integer constant or expression, the array also needs to be defined after use, it should be noted that when referencing an array element, the subscript can not be crossed, that is, you can not exceed the number of elements you define-1. C language allows the definition of multidimensional arrays, but not commonly used, two-dimensional arrays are arranged in line, the principle of the same dimension is basically the same, looks a bit like a determinant.
The character array, as its name implies, contains characters. There is no specific string variable in the C language, usually a character array to hold a string, and then input the array name to represent the starting address of the array, so you do not have to take the address character (&). C language has a lot of string processing functions, puts, get, strlen, strcpy, strcat, strcmp need to handle the string, which function to call.
The connecting character array involves the function, the function divides into two kinds, one is the library function, is the input and output function which we contacted before, is belongs to the Stdio.h library function, also has one kind of user-defined function, is the user to define according to own request function, can make the program easier. By procedure, the function is divided into a return value. A return value function returns an execution result to the caller after execution, without a return value function, which can be specified in the user-defined "null type", which is void main () {...}. If you follow the angle between the heart function and the modulated function, there is an argument function. Without parameter function, there is no argument between the key function and the modulated function, while the parameter function is the opposite, the key function transmits the value of the argument to the parameter of the modulated function.
The C language defines functions as parallel, that is, in a function body, it is not allowed to define another function in the nested, function calls itself, called recursive call, the application is more extensive.
The use of functions makes the function of C language rich and colorful, a variety of functions to make the program concise and neat, beginners C language Novice must be more familiar with the function and its application.
C language I do not touch the pointer, although the pointer is a very important part of the C language, but the pointer to understand for me as a beginner is not very easy, and in the absence of hardware based on the premise is not good in-depth understanding, Gao's advice to me is learning pointers to understand very difficult, Because you want to think of yourself as a computer, with a computer thinking, so this is the difficulty of pointers, in the future, I would like to know the pointer.
This is the first computer programming language I have come into contact with--c language, although I do not necessarily fully grasp the C, but it is very important to the Enlightenment of my programming language.
First contact with computer programming language--c language