Rules for Constructing Variable Names: C

Rules for constructing variable names are same for all the data types.

Related Read:
Rules for Constructing int, float, char constants: C

Rules for Constructing Variable Names: C


[youtube https://www.youtube.com/watch?v=sICsPcrZhQw]

YouTube Link: https://www.youtube.com/watch?v=sICsPcrZhQw [Watch the Video In Full Screen.]


Rules for constructing variable names

1. First character in a variable name must be an alphabet or an underscore( _ ).

2. Variable name can have alphabet, digits and underscore.

3. No commas, space allowed in variable name.

4. No other special symbols other than underscore is allowed.

5. C variables are case sensitive. Ex: name and Name are two different variables.

6. You can not use keywords / reserve words as variable name in C.

Valid Variable Names
_name
user_name
age20
iMac

Invalid Variable Names
9hundred
Micro soft
Apple$computers

Note: All these rules for constructing variable names apply for all the data types in C.

Rules for Constructing int, float, char constants: C

We’ve already learnt how to use int, float and char in our previous video tutorial. Now lets learn the rules to construct integer, float/real, character constants in C programming language.

Related Read:
Rules for Constructing Variable Names: C

Rules for Constructing int, float, char constants: C


[youtube https://www.youtube.com/watch?v=4o-ZJfi559Q]

YouTube Link: https://www.youtube.com/watch?v=4o-ZJfi559Q [Watch the Video In Full Screen.]


Rules for Constructing Integer Constants

1. It must have atleast 1 digit. We can have anything from 0 to 9.
2. If user enters decimal point, it’ll be discarded by the program and only the integer part will be stored in the int variable.
3. We can assign positive or negative digit by appending the digit with + or – symbol. If nothing is specified it’ll be considered as positive.
4. Comma, space etc are not allowed.
5. Allowed range for integer constant is -2147483648 to +2147483647 for Visual Studio and gcc compilers. For Turbo C / C++ compilers allowed range for integer constants is -32768 to +32767.

Invalid Integer Constants
10,000
10 000
999999999999

Rules for Constructing Real Constants

1. It must have atleast 1 digit. Anything from 0 to 9 is allowed. If decimal value is not specified compiler will insert 0s for decimal value.
2. It can be either positive or negative value. If + or – symbol is not specified, it’ll be considered as positive.
3. No comma or space allowed.

Rules for Constructing Character Constants

1. Character constant must have only single alphabetic or Single digit or special symbol and must be enclosed in single quote.

Invalid Integer Constants
“A”
“Microsoft”
‘Apple’
‘123’
“$%^”

Basic XML: Starting With Root Tag

Video tutorial explains the basics of XML and some rules to be followed to write the XML elements.
Also illustrating the way the raw XML files are displayed on the modern browsers.

Its a tag based language much like HTML, the difference is we can makeup our own tags.
XML is used to structure and describe the information.

Header Information

1
< ?xml version="1.0" encoding="utf-8"?>

it informs about the xml version and the encoding, i.e., the standard encoding utf-8
This is optional. But still recommended by W3C
And it is automatically generated by many tools, so lets keep it! It doesn’t hurt :-)

Full code

1
2
3
4
5
< ?xml version="1.0" encoding="utf-8"?>
<xml>
  IBM, Oracle, Apple, Maestro, Microsoft ..
  <!-- Google, Yahoo! -->
</xml>

Each XML document must have only 1 root tag.
Multiple root tag gives errors.

Rules To Write Elements(Tags) Names
Can begin with underscore or letter ..followed by zero or more letters, digits, hyphens, periods and underscores.

Video Tutorial: Starting With Root Tag: Basic XML


[youtube https://www.youtube.com/watch?v=6KUzJSEixXI]

YouTube Link: https://www.youtube.com/watch?v=6KUzJSEixXI [Watch the Video In Full Screen.]



Output in the browsers
this is on Chrome

1
2
3
4
5
6
This XML file does not appear to have any style information associated with it. 
The document tree is shown below.
<companynames>
IBM, Oracle, Apple, Maestro, Microsoft ..
<!-- Google, Yahoo! -->
</companynames>