সহজ সরল প্রথম C প্রোগ্রাম টি লিখতে শিখুন

Submitted by administrator on Mon, 01/02/2012 - 14:22

প্রথম C প্রোগ্রাম টি লিখতে শেখা

 

আমরা জানি C একটি উচ্চ-স্তরের প্রোগ্রামিং ভাষা এবং C প্রোগ্রামগুলি বাইনারি কোডে অনুবাদ করতে C কম্পাইলার (Compiler) দরকার হয় । বাইনারি কোড কম্পিউটার বুঝতে পারে এবং এক্সিকিউট করতে পারে। C প্রোগ্রাম লিখতে যে বেসিক জিনিসগুলি জানতে হবে --

  • The #include directive
  • Header files
  • Comments
  • The main() function
  • The return statement
  • The exit() function
  • The newline character (\n)
  • The void data type
  • Translating a C program into an executable file
  • Debugging

 

A Simple C Program
Let's have a look at our first C program, demonstrated in Listing 2.1. Later in this lesson you're going to write your own C program for the first time.

TYPE
 Listing 2.1. A simple C program.


  /* Simple C program */
  #include <stdio.h>

  main()
  {
     printf ("Suman, bah! This is my first C program.\n");
     return 0;
  }

This is a very simple C program, which is saved in a file called cprog01.c. Note that the name of a C program file must have an extension of .c. If you've installed a C compiler and set up the proper development environment, you should be able to compile this C program and make it into an executable file.

I set up my development environment in such a way that all C programs in this book can be compiled and made into DOS-based applications. For instance, cprog01.exe is the name of the DOS application made from cprog01.c. Note that .exe is included as the extension to the name of a DOS application program (that is, an executable file).

Also, on my machine, I save all the executable files made from the C programs in this book into a dedicated directory called C:\app. Therefore, if I type in cprog01 from a DOS prompt and press the Enter key, I can run the cprog01.exe executable file and display the message Howdy, neighbor! This is my first C program. on the screen. The following output is a copy from the screen:

C:\app> cprog01
Suman, bah! This is my first C program.
C:\app>

 

 

Summary
In this lesson you've learned the following:

  • Some header files should be included at the beginning of your C program.
  • Header files, such as stdio.h and stdlib.h, contain the declarations for functions used in your C program; for example, the printf() and exit() functions.
  • Comments in your C programs are needed to help you document your programs. You can put comments anywhere you like in your programs.
  • In ANSI C, a comment starts with the opening comment mark, /*, and ends with the closing comment mark, */.
  • Every C program should have one but only one main() function. The program execution starts and ends with the main() function.
  • The sequence of a carriage return and a line feed is carried out when the computer sees the newline character, \n.
  • The return statement can be used to return a value to indicate to the operating system whether an error has occurred. The exit() function terminates a program; the argument to the function indicates the error status, too.
  • The void data type can be used to modify the type of a return value for a function. Applying void to main() tells the operating system that the main() function does not return any value after termination.
  • Compiling and linking are consecutive steps that have to be finished before an executable file is produced.
  • Everybody, including yourself, makes mistakes in programming. Debugging is a very important step in your program design and coding.

In the next lesson you'll learn more about the essentials of C programs.

 

Comments

Related Items

Another Function for Writing: putchar()

Another Function for Writing: putchar()

C প্রোগ্রামিং এর putc() Function এর ব্যবহার

Using the putc() Function
The putc() function writes a character to the specified file stream, which, in our case, is the standard output pointing to your screen.

 

C প্রোগ্রামিংয়ের getchar() Function এর ব্যবহার

Using the getchar() Function
The C language provides another function, getchar(), to perform a similar operation to getc(). More precisely, the getchar() function is equivalent to getc(stdin).

 

The syntax for the getchar() function is

 

C প্রোগ্রামিংয়ে getc() Function এর ব্যবহার

Using the getc() Function
The getc() function reads the next character from a file stream, and returns the character as an integer.

 

The syntax for the getc() function is

 

C প্রোগ্রামিং এর double Data Type সম্পর্কে আলোচনা

The double Data Type
In the C language, a floating-point number can also be represented by another data type, called the double data type. In other words, you can specify a variable by the double keyword, and assign the variable a floating-point number.