Header Ads Widget

Ticker

6/recent/ticker-posts

Introduction to C Language - Part 1


             In this series, we will learn complete C programming language. Hello, welcome to my C language course. In this part I'll explain what actually is C Programming language.

 What Is C Programming?

C is a general purpose computer programming language designed by Dennis Ritchie at Bell Labs in 1972. Since then, C has evolved over time and now supports a variety of platforms including Windows, Linux, Mac OS X, Android, Raspberry Pi, and many others. Over the years, C has been widely used in embedded system computing – where low cost, small size, and long battery life are critical requirements.

How Do I Learn C?

There are numerous ways to learn C. You can take a course at school, enroll in an online program, or read books or articles about the subject. Each option comes with its own benefit and drawback. Courses at schools offer hands-on learning and allow students to work through real code examples. Programs online, while not providing direct instruction, generally feature step-by-step tutorials. Books provide detailed explanations of concepts and programs, and can be useful for those looking to learn at a faster pace.

Why Should I Study C?

If you are interested in developing your career as a programmer, or just want to get into a field that may lead to lucrative job opportunities—such as app development, gaming, automation, networking, etc.—then studying C could be recommended. In addition, if you wish to pursue higher education, consider taking courses in C programming. Many universities have programs dedicated to teaching C and related topics. As with any major academic topic, the curriculum varies significantly depending on what institution you choose.

C is a general purpose computer programming language. C is actually a full-fledged programming language rather than a collection of features as some languages might claim to be.

Its design philosophy is similar to ALGOL 60, K&R version 1, Pascal, PL/M, Modula-2, Oberon, Object Pascal, Ada, Smalltalk, Self, Tcl, VHDL, etc. A C program consists of a sequence of statements enclosed in braces { }. Example: print “hello world”

To start execution of C program first line is include directive which includes header file. Next step is to define variable, type definition and function.Example: int add(int x, int y);

After these things executable code begins. To execute this code we need to compile it. Compiling means translating source code written in human readable format to machine readable object code, mnemonics.

There are two kinds of compilation: static & dynamic. Static refers to translation of source code into object code without executing any program. Dynamic refers to translation of source into object code along with running of the actual program.

Compilation is different for various platforms. There are four major compilation steps involved in compilation. These are preprocessing step, lexical analysis, syntax analysis and assembly.

Preprocessing Step: This is translation of C programs into ASCII text. Preprocessing step eliminates comments and white spaces.

Lexical Analysis: This step converts character sequences to tokens. Lexical analyzer breaks down individual words and sentences and builds a tree data structure representing the syntactical elements of the source code.

Syntax Analysis: Syntax analyzer checks whether the program conforms to rules of grammar. If the program doesn't follow those rules then syntax analyzer generates error messages.

Assembly: Assembly is last step in compilation. Here individual instructions are converted into binary representation.

In C, variables are declared using declarations. Declaration specifies its type and size. Type determines storage duration whereas size refers to the number of bits that store value. Storage duration defines how long does the variable exist.

To just get an idea , how a simple c program to print a "hello world" looks like.. check below.


int main() {

printf("Hello World");

return 0;

}


We will learn in detail about all the topics and learn c language to all levels.

C programming language is a general-purpose computer programming language designed primarily for writing low-level system software. Its name comes from C, the first widely used assembly language. However, its syntax and semantics (its type system) are intentionally based on Algol 60 rather than on any particular assembly language; and many features from C99 are supported.

The primary goal of the C language is portability, both between different processor architectures and between operating systems, while remaining simple enough to allow quick implementation. Because the original version was developed at AT&T Corporation, the language was originally called ATT C. Many implementations exist today, including GNU C Compiler, Microsoft Visual C++ compiler, and Apple's LLVM compiler.

A number of compilers have been written specifically for embedded systems, including TinyCC, which targets microcontrollers at 8-bit, 16-bit, 32-bit, and 64-bit processors ranging from 8 MHz to 1 GHz. A few higher level languages, such as Python and Lua, claim to compile directly to machine code via a virtual machine.

Today, C is still commonly used for embedded systems. It is the standard language on many platforms, including Linux, Mac OS X, Windows, DOS, BSD Unix, various RTOSes, and even Android, where it serves as the native language of the Java Virtual Machine. It is less popular among desktop users, although some programs—such as GNU Emacs—are written entirely in C. Still, GCC remains the most widely used C compiler.

C stands for C-like languages and includes C++, Objective-C, Java, Go, and Python. All these languages have a similar syntax and their core principles follow the same basic structure. These languages were originally developed for Unix systems but they’re now used across many platforms including Windows, Android, Linux, iOS, and Mac OS X. A few of them are well known and widely used among programmers such as C, C++, Java, C, PHP, Ruby, and Perl.

2. Data Types

Data types are fundamental data structures that store information about variables. There are two different types of data types - numeric and nonnumeric. Numeric data types include integers, floating point numbers, and fixed point numbers. Nonnumeric data types include strings (characters), characters, Boolean values (true/false), and pointers.

3. Variables

Variables are names given to memory locations where we can store data. Once we assign a value to a variable, the value stored in that location becomes the current value of that variable. We use variables to store data temporarily while performing calculations or simply storing some piece of data.

4. Arrays

Arrays are special type of variables that allow us to store multiple pieces of data. When declaring arrays, we specify its size along with its contents. An array contains elements inside square brackets starting at zero index. To access array elements, we specify the index number after the brackets followed by the name of the array.

5. Loops

Loops are statements that repeat the same code block over and over again. We use loops to perform certain tasks repeatedly. Loops usually consist of initialization, condition statement, and action statement. Loops can run once or repeat indefinitely until terminated by an end statement.

6. Statements

A program consists of multiple statements. Each statement performs specific tasks. Some of the commonly used statements include if, else, switch, do-while, while, for, and return.

7. Control Structures

Control structures help our programs flow smoothly and prevent bugs. Control structures are statements that control the execution of other parts of the program. We use conditional statements to check conditions and make decisions based on those results. If-else statements are a popular control structure that checks for positive or negative conditions and makes a decision accordingly. Conditional statements are used to determine whether a command should execute or not. Sometimes, we may want to delay the execution of a command until later. In this case, we use the do-while loop.

8. Functions

A function is a set of statements that are grouped together to perform a specific task. Every function begins with the keyword “function” followed by parentheses containing arguments. A function may return something called its result. In the following example, we define a function named square( ) that takes two arguments x and y and returns x squared plus y squared.

int square( int x, int y ){ return x*x + y*y; }

The above function definition includes three parts: 

1) Function name – Square 

2) Arguments - x and y 

3) Body of the function – Returns the sum of x * x and y * y

In C++, functions are declared using the keyword “class” while defining them.

public class Square { public static void square( int x,int y){ return x * x + y*y;} }

Functions may have many forms including simple functions, procedures, methods, member functions, and inline functions.

            We will study in detail about all these topics one by one.

Post a Comment

0 Comments