Basic course of C language (ii) data types, variables, and operators (10)

Source: Internet
Author: User
3. Initialization of pointer type variable
For example:
Main ()
{
int *i=7899; /* Define integer pointer variable and initialize/*
float *f=3.1415926; /* Define floating point pointer variable and initialize/*
Char *s= "good"; /* Define character pointer variable and initialize/
.
.
.
}
Ii. Assignment of variables
A variable assignment is assigned to a specific value for a variable that is already described.
1. Assignment of a single variable
(1) integer variables and floating-point variables
Both of these variables are assigned in the following format
Variable name = expression;
For example:
Main ()
{
int A, m; /* Define local integer variable A, m*/
float N; /* Define local floating-point variable f*/
A=100, m=20; /* Assign value to variable * *
n=a*m*0.1;
.
.
.
}
Description
In Turbo C2.0, you can use a connection when assigning the same value to multiple variables.
For example:
Main ()
{
int A, b, C;
a=b=c=0; /* Assign value to a,b,c at the same time * *
.
.
.
}
(2) Character type variable
A character variable can be assigned a value in three ways.
For example:
Main ()
{
Char A0, A1, A2; /* Define local character type variables a0, A1, a2*/
A0= ' B '; /* Assign letter B to a0*/
a1=50; /* Assigns the number 2 (decimal ASCII value 50 to a1*/
A2= ' \x0d '; /* will enter assignments to a2*/
.
.
.
}
(3) Pointer type variable
For example:
Main ()
{
int *i;
Char *str;
*i=100;
Str= "Good";
.
.
.
}
*i says I is a pointer to an integer, that is, *i is an integer variable and I is an address that points to the integer variable.
*STR indicates that STR is a character pointer that retains a character address. At initialization time, STR has no special value, and when executing str= "good", the compiler reserves a space in the target file to hold a "good\0" string, and assigns the address of the first letter "G" of the string to STR, where the end of the string is automatically added by the compiler.

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.