|
C Programming Tutorials
Basics of C:
Facts about C
Why to Use C
C Program File
C Compilers
Program Structure:
Simple C Program
C
Program Compilation
Basic DataTypes:
DataTypes
Modifiers
Qualifiers
Arrays
Variable Types:
Local Variable
Global
Variable
Storage Classes:
auto storage class
register storage
class
static storage
class
extern storage
class
Using Constants:
Defining Constants
The enum Data Types
Operator Types:
Arithmetic Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc
Operators
Control Statements:
Branching
Looping
Input and Output:
printf() function
scanf() function
Pointing to Data:
Pointers and Arrays
Pointer
Arithmetic
Pointer Arithmetic
with arrays
Functions:
Using functions
Declaration and
Definition
Strings:
Reading and Writing
Strings
String Manipulation Function
Structured DataTypes:
Structure
Pointer to Structure
Working with Files:
Files
Basic I/O
Bits:
Bits Manipulation
Bits Field
Pre-Processors:
Pre-Processors Examples
Parameterized Macros
Macro
Caveats
Useful Concepts
Built-in Library Functions:
String Manipulation
Function
Memory Management
Function
Buffer
Manipulation
Character
Functions
Error Handling
Functions
Soft Skills
Communication Skills
Leadership Skills
.........More
|
C Programming Tutorials
Program Structure
A C program basically has the following form:
-
Preprocessor Commands
-
Functions
-
Variables
-
Statements & Expressions
-
Comments
The following program is written in the C programming
language. Open a text file hello.c using vi editor and put the following lines
inside that file.
#include <stdio.h>
int main()
{
/* My first program */
printf("Hello, TechPreparation! \n");
return 0;
} |
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation. Like #include <stdio.h> is a preprocessor command which tells a C
compiler to include stdio.h file before going to actual compilation. You will
learn more about C Preprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have
one or more functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integer value when it exits. This integer value is returned using
return statement.
The C Programming language provides a set of built-in functions. In the above
example printf() is a C built-in function which is used to print anything on the
screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation.
You will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements are
expressions, assignments, function calls, or control flow statements which make
up C programs.
Comments:
Comments are used to give additional useful information inside a C Program. All
the comments will be put inside /*...*/ as given in the example above. A comment
can span through multiple lines.
Note the followings
-
C is a case sensitive programming language. It means in C
printf and Printf will have different meanings.
-
C has a free-form line structure. End of each C statement
must be marked with a semicolon.
-
Multiple statements can be one the same line.
-
White Spaces (ie tab space and space bar ) are ignored.
-
Statements can continue over multiple lines.
C Program Compilation
To compile a C program you would have to Compiler name and program files name.
Assuming your compiler's name is cc and program file name is hello.c, give
following command at Unix prompt.
This will produce a binary file called a.out and an object
file hello.o in your current directory. Here a.out is your first program which
you will run at Unix prompt like any other system program. If you don't like the
name a.out then you can produce a binary file with your own name by using -o
option while compiling C program. See an example below
Now you will get a binary with name hello. Execute this
program at Unix prompt but before executing / running this program make sure
that it has execute permission set. If you don't know what is execute permission
then just follow these two steps
$chmod 755 hello
$./hello
This will produce following result
Hello, TechPreparation! |
Congratulations!! you have written your first program in "C".
Now believe me its not difficult to learn "C".
NEXT >> Basic
DataTypes
Have a Question ?
post your questions here. It
will be answered as soon as possible.
Check
C Aptitude Questions
for more C Aptitude Interview Questions with Answers
Check
C Interview Questions
for more C Interview Questions with Answers
|