Topics in C Programming.

Topics: Programming language, C, Pointer Pages: 13 (3554 words) Published: September 2, 2013
Topics in C Programming
Bob Hain
Introduction
This document is not intended to be a text on C programming. Because many of you may not have had the opportunity to use or practice C programming, we are attempting to provide a brief description of some of the elements of C which you will need in your laboratory work. We will leave out many topics but will try to provide simple, although sometimes incomplete, explanations of some of the basic elements of C. Why C?

The computer industry is changing rapidly. Although changes in hardware are easier to observe, changes in the software environment are no less striking. The FORTRAN and BASIC programming languages have served the scientific community for many years. These language are highly optimized for numerical calculation and are still in wide-spread use. But with the introduction of small powerful computers, software needs began to change. These computers were applied to many tasks not solely based on numerical manipulation. Two examples of such applications are the acquisition of experimental data and control of the experimental process. The FORTRAN and BASIC languages were extended to address many of these changing needs, but modern languages such as C began to spring into use. The speed with which C has developed has made it impossible for the University to introduce it early in the curriculum and to build on it throughout your education. Because of C's acceptance in industry and research institutions, we feel that you should be exposed to it. We do not expect you to become an expert in C programming. In fact, we stress that this course is about experimental techniques for heat transfer studies. An introduction to C programming falls within the scope of such a course, but it is not its main objective. We hope that you will find this experience pleasant and rewarding. A Simple C Program

main()
{
}
It has no input, no output, and does nothing. I didn't claim it was a useful program, but it is the simplest one I could think of. What is demonstrated here are the minimum requirements of a C program. All C programs must have one function called main. The syntax of a function consists of a name followed by a set of parentheses and a set of braces. The braces delimit a group of statements (null in this case). We will encounter many braces. The program above could have been written as:

main() { }
This is equally acceptable to the C compiler, but it is not good style. While I will not make many explicit comments about style, try to be aware of the issue. Formatted Output
The next C program is often the first one people ever see. It is the first program presented in The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie (Prentice-Hall, 1978).
main()
{
printf("hello, world\n");
}
The output of this program is:
hello, world
While this program is only slightly more utilitarian than the last (it at least has output), it demonstrates a few more features of C programming. The printf() statement provides output to the screen. All statements must end in a semicolon! The most common error in C programming is to omit the semicolon. Such an omission causes the compiler to go berserk, reporting some sort of nonsensical error message a line or two later in the program. The first thing to do when things go wrong is to check that all your statements end with a semicolon. Another point to observe is that, ignoring all the stuff in the parentheses and the semicolon on the end, the statement reduces to printf(). This, of course, is a function. C is a very simple language that has very few built-in features. This does not imply that it is a limited language. The simplicity of C is its strength. A great amount of C programming consists of calling functions. These functions...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Essay on C Programming for Embedded Microcontroller Systems
  • Essay about C Programming
  • Programming in C# Essay
  • programming C Essay
  • C Programming Tutorial Essay
  • Computer Programming (C++) Essay
  • A Project Report On C Programming Essay
  • Essay on The C Programming LanguageHistoryC Was Developed

Become a StudyMode Member

Sign Up - It's Free