Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Here is a simple C program that outputs the text "Hello, World" to the standard output (e.g., screen, printer, file, etc.). Previously, we were only interested in compiling and running the program. Now we want to look at the program structure, what it does, how it does it, etc. Here is the program.
Here is the C code.
Here is the output of the C code.
3. Case sensitivity
In file systems, programming languages, etc., a name is often called an identifier as the name is used to identify some idea or concept.
4. Uppercase, lowercase, etc.
All letters have an uppercase and a lowercase version.
The uppercase letters are ABCDEFGHIJKLMNOPQRSTUVWXYZ.
The lowercase letters are abcdefghijklmnopqrstuvwxyz.
5. Names
A name in a programming language is ofter called an identifier is the name "identifies" some concept being used.
The case rule for names refers to what types of uppercase and lowercase letters are allowed.
The name "myname" is in lowercase.
The name "MYNAME" is in uppercase.
The name "mYnAmE" is in mixed case.
The name "MyName" is in camel-case, where each word within the name is started in uppercase and every other letter is in lowercase. This is sometimes called inter-caps.
6. Underscores
Many languages permit the underscore character "_" to be used in a name. This would allow the following as named identifiers.
"my_name"
"MY_NAME"
"My_Name"
Question: Are the identifiers/words "Main" and "main" the same?
7. Upper/lower case
8. Minuscule and magniscule
Like traditional security codes, ancient texts had no spaces and only one type of letters.
Languages were not standardized.
9. Charlemagne
Charlemagne, Emperor of the Holy Roman empire, ordered that lowercase letters be created and standardized along with uppercase letters.
At that time, they were called miniscule and magniscule.
The publication of dictionaries standardized the language.
10. Upper and lower case
There are two types of cases for letters: uppercase and lowercase
Lowercase letters: abcdefghijklmnopqrstuvwxyz
Uppercase letters: ABCDEFGHIJKLMNOPQRSTUVWXYZ
From where did lowercase letters come from?
11. Case sensitivity
In a case-sensitive notation, case matters.
In a case-insensitive notation, case does not matter.
A case sensitive notation means that the following names are all different.
A case insensitive notation would consider the all of the above the same identifiers.
12. URL's
Is a URL (Uniform Resource Locator) case-sensitive?
Example:
http://168.20.203.67/VITA.NV/default.asp
For a Linux web server, yes.
For a Microsoft web server, no.
Note: The domain name is not case sensitive, but the path within the domain depends on the web server operating system used.
13. Files
Is a file reference case-sensitive?
For a Linux web server, yes.
For a Microsoft web server, no.
For example, image.jpg is different than image.JPG on a Linux web server but the same on a Windows web server.
14. Windows file system
The Microsoft Windows file system is case-retentive in that it retains the case of a name, but does not use it for matching purposes.
Thus, image.jpg would match image.JPG.
The last of these names, delete, might be reserved as a keyword. The others could then be used in a program in a case sensitive language.
How many ways are there to write the word "delete" in a case-sensitive manner where all would be the same if a case-insensitive match were used?
The word "delete" has 6 letters.
There are 2 possibilities for each letter, the upper-case letter or the lower-case letter.
The product 2*2*2*2*2*2, or 26, is 64.
15. Programming languages
When programming, does it make a difference which case you use for identifiers?
In C, C++: yes.
In Java, C#: yes.
In Python: yes.
In JavaScript: yes.
In Visual Basic, VBA, VBScript: no.
Most modern languages are case-sensitive.
Visual Studio will change the case in the editor to the case of the declaration.
16. Case conventions
The programming language C is case sensitive.
17. C: Reserved words
A reserved word is a word (name, identifier) in the language that has a special meaning and cannot be used in a program as a programmer-defined or library-defined identifier or name except as specified by the rules of the programming language.
18. Reserved words
Here are some reserved words for C.
auto break case charconst continue default dodoubleelse enum extern float forgotoif inline int long
register restrict return short signed sizeof static struct
switch typedef union unsigned void volatile while
19. Library identifiers
A library identifier is a word that is part of a code library. It can be redefined, but that might cause problems with the program as it was intended to be run.
The word main is a reserved word in C.
The identifier "String" might be what you want.
You type "string".
Will it work?
It might work. There may be library names "string" and "String".
You may get the wrong one and may not notice for a while that it is not the right one.
20. Syntax
21. Incorrect syntax
A syntax of a programming language is comprised of the grammar and punctuation rules for the programming language.
Incorrect syntax:
The student were good.
What is the right syntax?
It could be one of the following (or something else).
The student was good.
The students were good.
If you make a syntax error, how can the compiler decide what you meant?
The compiler can only detect errors as inconsistencies.
It is up to you, the programmer, to decide what should be done.
22. Examples of identifiers
An identifier name starts with a letter or underscore and is followed by letters, digits, or underscores.
Notice again the use of blank lines and spaces. In a program, white space is
blank lines and spaces and indentation that is used to make the program more readable.
The term "white space" comes from the fact that if you are using white paper, any space is the color of the paper (i.e., white).
Indentations are important for humans to see the structure of a program.
Blank lines are used to visually separate parts of a program.
The computer does not care. Your boss does. Your professor does. And, you do, if your programs are important to you.
24. Consistency
The most important programming style consideration is to be consistent.
Being consistent means always doing similar things in the same way.
25. White space
Look at the program, again.
Note the following.
Blank lines are used to separate parts that are related.
Subparts are indented consistently.
There is exactly one space before the "{".
There is no space after main and before the left parentheses "(".
A subpart should be indented consistently, just as in an outline.
26. Indentation
In most programming languages, there is more than one way to indent. Another way to indent the above program, and a style used by many programmers, is as follows.
Which is better? It all depends. The most important thing is that whichever way you chose to indent, be consistent.
Note: To write a good program, you need more than good "indentions"!
27. Detected errors
You should read the error message and make a decision as to what to do.
"lexical error" means "punctuation error"
"string constant" means "string literal" (text)
"not properly terminated" means "not ended properly"