C Language Basics 1

Source: Internet
Author: User

C Language Basics 1

Four elements of a function: name, input, output, processing.

source file (extension. cpp)

(The comment is behind the double slash)

Grammatical features:

Most of the code is written in curly braces {}.

The end of the sentence is usually terminated with a semicolon.

Sensitive to case

Attention:

Quotation marks, semicolons, commas, etc. must be written in the English state.

Chinese is written in double brackets only.

Function:

1, the first line of the format #include<stdio.h>

#include <stdio.h>

Include includes

Stdio Composition:

STD STANDDRD Standard

I input inputs

o outpput Output

. h Head Header file

2, the second line of the format void main ()

void Main ()

void null value, no return value

Main fixed, name

Attention:

Parentheses are not limited, there are no semicolons after parentheses

3, printf ("");

1) Print output, only content in parentheses

Example: printf ("Please enter your age");

2) Output value

Example: int n=5;

printf ("You are%d years old next year", N);

Where%d is a bitwise OR placeholder

int is an integer data type

4, scanf ("",);

int n;

scanf ("%d", &n)

Where%d is the input format

& is take address symbol

Attention:

scanf ("",) do not write in quotation marks, generally write only the placeholder.

Cases:

#include <stdio.h>//standard input output head means to include a header file of a marked//quasi-input to the program. The main function, void is to represent no//any return value, main is the name of the main function, the main function is the entry of the program, there is only//has a

void Main ()

{

Print using printf (""); semicolon end

printf ("Hello world!");

int n;//defines a variable with an integer type of int type n,n can temporarily store integer data with//

scanf ("%d", &n);

printf ("%d", &n);

}

#include <stdio.h>

void Main ()

{

int n=5, m=10;

printf ("The forest lived%d dwarfs," N);

printf ("One day, there are%d Snow White in the Forest", m);

n=7;

M=1;

printf ("The forest lived%d dwarfs," N);

printf ("One day, there are%d Snow White in the Forest", m);

}

#include <stdio.h>

void Main ()

{

int n,m,x;

printf ("Please enter your age, your father's age");

scanf ("%d%d", &n,&m);

X=m-n;

printf ("Your father is%d years older than you", x);

}

#include <stdio.h>

void Main ()

{

int n;

printf ("Please enter your age");

scanf ("%d", &n);

n=n+1;

printf ("You are%d years old next year", N);

}

#include <stdio.h>

void Main ()

{

int a,b,c;

printf ("Please enter your age");

scanf ("%d", &a);

printf ("Please enter your father's age");

scanf ("%d", &b);

printf ("Your Age is%d", a);

printf ("Your father's age is%d", b);

C=b-a;

printf ("Your father is%d years older than you", c);

}

#include <stdio.h>

void Main ()

{

int a,b,c,s,x,y;

printf ("Pool radius, square radius");

scanf ("%d%d", &a,&b);

C=6*a;

S=3*b*b-3*a*a;

X=10*c;

y=50*s;

printf ("Pool fence length%d", c);

printf ("Square area%d", s);

printf ("Pool fence cost%d", x);

printf ("Square Tile cost%d", y);

}

Data type

(1) Int integer type

(2) Double decimal

(3) Float decimal, single-precision floating-point number

(4) Char character type

Char s[]= "Hello"

Defines a person with a length of string, in square brackets to write a number greater than the length of a character in quotation marks.

printf ("%lf", b) LF is 6 digits after the decimal point

printf ("%s", B) s is a string

printf ("%c", B) c is a single character

Double is twice times the number of flout digits.

C Language Basics 1

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.