Preliminary understanding of C language

Source: Internet
Author: User

#include <stdio.h>//contains header file, standard input output header file standard input outputs;

#include <math.h>

void Main () {

printf ("This is a C program\n");

}

The main function is the entrance to the C language program.

{} Indicates the starting point of the main function.

printf ("This is a C program\n");//The text within the double quotation marks is printed to the screen.

\ nplease print a carriage return.

Type (data type):

char,unsigned char,signed Char: up to 1 bytes;

short,unsigned Short int: 2 bytes;

int,unsigned int unsigned integer (positive integer): 4 bytes (32-bit machine);

long,unsigned Long Integer: 4 or 8 bytes (length greater than or equal to int);

Float single-precision floating-point number: 4 bytes;

Double double-precision floating-point number: up to 8 bytes;

What the data type means: It means more efficient memory space savings.

SCANF is to obtain data from the keyboard;

printf fetches data from memory;

The rules for variable naming in C language: Each variable must begin with a letter and an underscore, consisting of letters, underscores, and numbers.

The case is two different characters.

Cannot use the keyword of c to do variable name.

The concept of constants:

A constant is a quantity that cannot be changed. Because the literal value of a constant represents its numeric size, it is also called a literal constant. Constants can represent values of various data types. Its data type can also be learned directly from its literal form.

Constants constants:

Const: Add the const keyword before a variable to become a constant.

The value of a constant that cannot be changed once initialized.

Constants must be initialized at the same time as they are created.

The concept of a variable:

A variable is a quantity that can be changed. Variables are made up of two parts: variable names and variable values. Variable teacher an identifier; the value of a variable is a data value.

When defining a variable in the C language: int const and const int are the same or indifferent;

The function of "%-8d" in C language is:

Defines the output format so that the output int data occupies at least 8 positions and is positioned from the leftmost end of the 8 position.

If the displayed data is less than 8 characters, add a space to complement the 8 locations;

If the data displayed is more than 8 characters, the subsequent position continues to occupy.

The function of "\ T" in the C language is the equivalent of a TAB key, which is intended to align the output results.

Here are two simple examples in C language:

Implement subtraction:

#include "stdafx.h"

int main (int argc, char* argv[])

{

int a=0;

int b=0;

printf ("Please input a,b\n");

scanf ("%d", &a);

scanf ("%d", &b);

printf ("%d+%d=", a,b);

printf ("%d\n", a+b);

printf ("%d-%d=", a,b);

printf ("%d\n", a-b);

printf ("%d*%d=", a,b);

printf ("%d\n", a*b);

printf ("%d/%d=", a,b);

if (b!=0) {

printf ("%d\n", A/b);

}else{

printf ("Please re-enter");

}

return 0;

}

The 99 multiplication table in C language:

#include "stdafx.h"

int mian (int argc,char*argv[]) {

int a[9];

int b[9];

int i;

Int J;

for (i=1;i<=9;i++) {

A[i]=i;

printf ("\ n");

for (j=1;j<=i;j++) {

B[j]=j;

printf ("%d*%d=%-3d", B[j],a[i],b[j]*a[i]);

}

}

return 0;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.