C second introduction class

in #c7 years ago

Following our last thread https://steemit.com/c/@debuglove/a-small-introduction-to-c, we will continue with a small code so you can format better your text and write well documented code.

-Escape Sequences:

In our last example lets suppose we would like to print. Hello "nice" Reader at the screen. Ops, what happened, is the compiler nuts? Nah. What happened is simply the word "nice" wont be on the escope of the function, and the compiler doesnt understand what "nice" means. thats where our escape sequences and character escapes enter in action. To solve this problem all we had to do is replace the code:

    printf("Hello "nice" Reader\n");

For the code:
    printf("Hello \"nice\" Reader\n");

To our main task at hand, which is format text, the most important will be the following:

\" - get quotation marks inside string literals
\' - writes a character literal for the character '.
\\ - writes a stringfied backslash so it wont be interpreted as a escape sequence
\a  - rings the terminal bell of your CPU
\b - backspace character
\f - formfeed character
\n - newline character
\r - carriage return character
\t - horizontal tab character
\v - vertical tab character
But one image is worth a thounsand words. So lets take a small peek

img1.jpg

Our vertical tab and formfeed characters are relics of and old era, which would help you format text in printers. So chances are you wont need them very much.

-Commenting:

Now, everything looks neat, but good code needs be well documented, and we cant do that at the software or console application itself can we?

We can do it commenting just one line:

    //this is a comment

Or we can comment multiple lines:

    /* multiple

    lines
    Commenting */

Everything after the single line commenting or inside the multiple lines commenting characters, will be ignored by the compiler. And now, you can comment and document your code at your favorite IDE.

-Identifiers:

To complete our introduction lesson today we will take a brief look at how we can identify the data types we create in C. Our native C datatypes, will contain different types of data, like a text, a number or a fraction. But we cant just assign that value to the C datatype, like:

    int = 7;

Can we? Thats why we must give that datatype a identification:
    int number = 7;

Since C is a case sensitive language, identifiers like:
    char C = 2; char c = 2;

Will be 2 different identifiers. Lets say you assign char C = 4, char c will still remain as 2.

Identifiers cannot start with a number digit, but may contain underscore. Also you may not use the C reserved keywords as identifiers:

        auto    else    long    switch  break   enum    register    typedef
    case    extern  return  union   char    float   short   unsigned
    const   for signed  void    continue    goto    sizeof  volatile
    default if  static  while   do  int struct  _Packed
    double
    
Im going a bit slow, since im also still learning and getting used with steemit and its format style.

Next class, we will go a little deeper into C data types.
See you soon!

Coin Marketplace

STEEM 0.15
TRX 0.12
JST 0.025
BTC 56204.99
ETH 2395.80
USDT 1.00
SBD 2.38