top of page
Search

Let us C with MP.T -- Part 1

Did I just plagirize Kanetkar for that title? Yes, Yes I did.


But this writer is definitely different than Kanetkar tho, because

A) she doesn't have a phD (yet :))

B) She is also figuring out this weird language along with you on this journey.

Makes one question if these are actually pros or cons 🤣.


Now I will go ahead and convice y'all why we need to learn C while there are so many other computer languages out there.

  1. Because it is in this writer's course work and she needs to learn it before her mid sem exam

  2. C is a foundational language that can help you learn other programming languages, such as C++ and C#, and understand how to program with them.

  3. C is a powerful language that's used in many applications around the world, including system programming, game development, networking protocols, scientific computing, embedded systems, and database management systems.


Conivinced you enough? Now let's start.

Few words you need to know the meaning of before beginning

  1. Compiler - This is the system which converts what we write into something the machine can understand. It is in theory a translator for the computer.

  2. Run - Executes the program


Moving on to the components of this language --- Constants , Variables, Keywords.


CONSTANTS - An entity that doesn't change

Types of Constants --

Now let's talk about Primary constants in detail

Integer constants

  1. Allowable integer range as input = (-2147483648) to (214748647).

  2. If no sign precedes it, it is assumed to be positive.

  3. Must not have a decimal point.

  4. No commas or blanks are allowed withing an integer constant.


Real constants

  1. Must have a decimal point (i.e 9 should be written as 9.0).

  2. Default sign is positive if not mentioned.

  3. No commas or blanks are allowed within a real constant.

For exponential representation --

  1. In exponential form, the real constant is represented in two parts, the part appearing before 'e' is called mantissa , and the part following is called exponent.

0.000342 can be written as 3.42e-4.

2. Range is (-3.4e38) to 3.4e38.

3. The mantissa and exponential must be separated by 'e' or 'E'.


Character constants

  1. Must be a single alphabet, single digit, single special symbol enclosed within single inverted commas.

  2. Both the inverted commas should point to the left. Egs - 'A'.


We will discuss about secondary constants in future blogs...

Now moving on to

VARIABLES -

Rules for constructing Variables -

  1. The first character in the variable names must be an alphabet or underscore (_).

  2. No commas or blanks are allowed within a variable name.

  3. No special symbol other than an underscore ( like iit_ism ) can be used in variable name.

  4. It is compulsory to declare the data types of the variables while coding ( will be discussed again)


KEYWORDS-


Keywords are the words whose meaning has already been explained to the C compiler (or to the computer). There are 32 keywords available in C.

These keywords , in general ,should not be used as variable names.

(It's like having too many 'Priya' in one class, everyone around gets confused)

Major keywords used often are --

  1. int -- used to define integer data type

  2. float -- used to define decimal / real data type

  3. double -- used to define long numbers

  4. char -- used to define character


Now let us write out first program, for this we need a compiler. As this is the very beginning of learning this language it is easier to just use an online compiler like


It's kinda a cutesy tradition to always start your coding journey by printing "Hello World". The code for it is -

There are several new words in this ik, all these components will be discussed in detail in future.

One thing to be remembered is the command and its syntax --- printf(" type what you want as output");

This command is used repeatedly during C programming to show any output on the screen.

In brief if I have to explain all the words used it is --

  1. #include<stdio.h> is a preprocessor directive/ Header file

  2. main () is a function. A function, in general, is nothing but a container for a set of statements.

    All the statements belonging to main() must be enclosed within curly brackets { --} Just put curly brackets right after main () and at the very end of ur code.

  3. Like the functions in a calculator, functions in C also return a value. main() function always returns an integer value hence there is an int before main().

    In this case (and most other cases) we will be returning 0.


This covers the atmost basic of this language. Next blog we will cover more about this language so keep your eyes peeled!

Now because this writer, like always ,is lazy to write a proper conclusion, lets end with a meme.



 
 
 

Comments


bottom of page