সহজ সরল প্রথম 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

মডুলার C প্রোগ্রামিং (Modular C Programming)

কেবল মাত্র একটি ফাংশন দিয়ে কোনো বড়ো জটিল সমস্যা সমাধানের চেষ্টা করা ভাল প্রোগ্রামিংয়ের পদ্ধতি নয়। সঠিক পদ্ধতি হ'ল সমস্যাটিকে কয়েকটি ছোট ছোট এবং সরল টুকরো করে ফেলা যাতে তা আরও বিশদে বোঝা যায় । তারপরে এই ছোট এবং সরল সমস্যাগুলি সমাধান করার জন্য ছোট ছোট ফাংশন ব্লক তৈরি করা এবং পরে সেগুলি নিয়মানুযায়ী সংযোজিত করা ।

Programming Style

Programming Style

In this section, I'd like to briefly highlight some points that will help you write clean programs that can easily be read, understood, and maintained.

Exercises : Answer the following Question

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

Question and Answer

    Q Is the C preprocessor part of the C compiler?

    A No. The C preprocessor is not part of the C compiler. With its own line-oriented grammar and syntax, the C preprocessor runs before the compiler in order to handle named constants, macros, and inclusion of files.

Compiling Your Code Under Conditions

Compiling Your Code Under Conditions

You can select portions of your C program that you want to compile by using a set of preprocessor directives. This is useful, especially when you're testing a piece of new code or debugging a portion of code.