0% found this document useful (0 votes)
317 views6 pages

Introduction to C Programming Basics

Uploaded by

jeonhiba59
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
317 views6 pages

Introduction to C Programming Basics

Uploaded by

jeonhiba59
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Science ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ICS P 2

Chapter 8 - Getting Started with C


What is a Program?
●​ A well defined set of instructions given to the computer.
●​ All tasks performed by a computer are controlled by a computer program.
●​ Written in programming languages.
Examples: • Microsoft Word​ • Adobe Photoshop​ ​ • Skype
Programmer: A person who develops a program is known as Programmer.
History of C Language
●​ C is a popular general purpose language
●​ Developed by Dennis Ritchie at AT & T Bell Labs in 1972
●​ C language was derived from earlier programming language called B
●​ B was developed by Ken Thomson in 1969-70
AU
●​ provided the basis for the development of C
●​ C language was originally designed to write system program under Unix OS
●​ Earlier version of C was known as K & R (Kernighan and Ritchie)
●​ American National Standard Institute (ANSI) developed a standard version of C language
in late 1980s → ANSI C
●​ New version provided many features that were not available in the older version
Characteristics of C Language
1. Convenient Language
●​ Provides many facilities in easier ways that are difficult to use in low-level languages
●​ Write complex programs more easily as compared to low-level languages
N
2. Well-Structured Language
●​ Syntax is very easy to use
●​ Program written in C language are easy to maintain and modify
3. Machine Independence
●​ Program written in high-level language can be executed on any types of computers
Example - A program written in C language can be executed on Intel and Motorola processors
4. Modularity
●​ Breaking a large program into smaller units or modules
●​ Modules in C are called functions
●​ Modules are more manageable than one large program
●​ Modules can be independently implemented and tested

1
Computer Science ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ICS P 2

5. Case Sensitivity
●​ Differentiate uppercase and lowercase words
●​ Makes it easier to maintain the source code
●​ All keywords are written in lowercase e.g. while, for etc.
6. Hardware Control
●​ Provides close control on hardware
●​ Used to write efficient programs to control hardware components of computer system
7. Small Language
●​ Has small number of keywords and programming controls
●​ Very powerful language for developing different types of program
8. Fast Code Generation
●​ Compilers of C language generate very fast code.
AU
●​ The code executes very efficiently → programs take less time to execute

Why do we Write Program in C language rather than Machine Language?


1. Easier to Write
●​ C is a high level language
●​ Instructions of C are similar to English language that are easy to understand
BUT
●​ Machine language is low-level language
●​ Program written in machine language consist of 0s and 1s
●​ Very difficult to write, modify and manage programs in machine language
2. Machine Independence
N
●​ Program written in C language can be executed on different types of computer
BUT
●​ Program written in machine language is machine-dependent
●​ It can only work on the computer it was designed for

TURBO C++

●​ Compiler used for C language is called Turbo C++


●​ Provides a complete Integrated Development Environment (IDE) known as TC editor
●​ Used to create, edit, save , compile and run C programs
●​ Provides a powerful debugger feature → detecting and removing errors in programs
●​ Type TC on DOS prompt and press Enter key to Start IDE

2
Computer Science ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ICS P 2

●​ The menu bar of IDE contains menus to create, edit, compile, execute and debug C
program
●​ The user can open the menu by clicking it with the mouse.
●​ The user can also press a combination of the ALT key and the first highlighted character
of the name of the menu.
●​ For example, ALT+F is used to open File menu

AU
Creating and Editing a C program
●​ Process of Writing C program is known as Editing
●​ This process includes writing, modifying and deleting program statements
●​ Part of Turbo C++ IDE that is used to write C programs is called Edit Window
●​ A new edit windows can be opened by selecting File>New option from menu bar
N

●​ Edit has a double lined border


●​ Cursor blinks in the window
●​ Position of the cursor indicates the starting point to write a program

3
Computer Science ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ICS P 2

●​ User can expand window by clicking the arrow in the upper right corner

Saving a C program
●​ Process of storing the program on disk
●​ A program should be saved on disk to be used repeatedly
●​ C programs are saved with .C extension

Procedure to Save a C program Using Turbo C++


●​ Select File>Save. The Save As dialog box will appear
●​ Default name [Link] appears
●​ Enter the file name
●​ Enter the path to save file
●​ Click OK. The program will be saved at specified location

AU
N
Compile a C program
●​ Process of converting source program into object program
●​ Converted program save with .obj extension
●​ Source program cannot be compiled if it contains any syntax error
●​ Compiler generates error message to describe the cause of error

Procedure to Compile C program Using Turbo C++


●​ Select Compile>Compile

4
Computer Science ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ICS P 2

●​ Program will be translated into object program


●​ In case of error, compiler will generate error message

Linking a C program
●​ Linking is process of linking library files with object program
●​
●​
●​
●​
●​
●​
AU
These files are used to perform different tasks such as input/output
A library file must be linked with the object file before execution
Linker is a program that combines the object program with additional library files
Linker generates error message if the library file does not exist
A new file is created with .exe extension if the process of linking is successful
The linker can be started in Turbo C++ by selecting Compiler > Link from the menu bar

Executing a C Program
●​ Execution is the process of running an executable file
●​ The C program can be executed after compiling and linking
●​ The program must be loaded into memory to execute
●​ In Turbo C++,
N
○​ The program can be loaded in the memory by selecting Run > Run from the
menu bar or pressing CTRL+F9.
○​ The screen flickers for some time when a program is executed.
○​ The output screen displays the output of the program and disappears.
○​ The user can display the output screen by selecting Window > User Screen or
pressing ALT+F5

5
Computer Science ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ICS P 2

Necessary Steps to Prepare a Program for Execution

AU
N

Common questions

Powered by AI

Preparing a C program for execution in Turbo C++ involves several steps. First, the program is written in the editor and saved with a .C extension. The user selects 'File > Save' in the IDE to input the file name and storage path. The next step is compiling the program by choosing 'Compile > Compile' to transform the source code into object code. If there are syntax errors, the compiler generates error messages for correction. Finally, linking is performed by combining the object code with necessary libraries, producing an executable file. This executable file can then be run, displaying the program's result .

C programming language is preferred over machine language because it is a high-level language with instructions similar to the English language, making it easier to understand, write, and manage. In contrast, machine language consists of binary code (0s and 1s) that is directly executed by the computer's CPU but is very difficult to write, modify, and manage, given its complexity and lack of readability. Moreover, C enhances machine independence, as programs written in C can run on various hardware platforms, unlike machine-specific code .

C programming language enables machine independence by allowing programs written in C to be executed on different types of computers without modification. This is crucial as it increases the portability and reusability of programs, reducing development time and cost when transferring applications between different hardware platforms .

Turbo C++ IDE provides a comprehensive environment for creating, editing, saving, compiling, and executing C programs. It includes an Edit Window for writing and modifying program statements. Users save programs through a straightforward menu option which involves specifying a name and path for the file with a .C extension. Compilation is enabled via menu selections that convert source programs into object programs, ensuring any syntax errors generate helpful error messages. The linking process in Turbo C++ involves combining object programs with library files to prepare executable files, and execution is initiated within the IDE, effectively displaying program output .

Modularity in C programming is crucial because it allows large programs to be broken down into smaller, more manageable units called functions. This approach simplifies the development and maintenance of programs, facilitates debugging, and enhances code readability. Modularity supports the independent implementation and testing of functions, making it easier to scale and modify programs as needed .

The C programming language is popular due to its combination of various characteristics. It is a convenient language that provides many facilities more easily than low-level languages, enabling complex program writing. C is well-structured, having a syntax that is easy to use, making programs easy to maintain and modify. The language is machine-independent, allowing programs to run on different types of computers. Additionally, C is modular, allowing large programs to be broken into manageable functions, and case sensitivity allows for clear maintenance of source code. C offers close hardware control, making it efficient for system programming, and its small number of keywords makes it easy to learn. Furthermore, C compilers generate fast and efficient code execution .

Linking in C programming combines the object code created by the compiler with library files necessary for executing certain tasks, such as input/output operations. This step is crucial as it resolves external references in the code, producing an executable file with an .exe extension. Without linking, a program cannot run because it lacks the complete set of instructions needed to perform all required functions. The process is facilitated by a linker that verifies all components are available, generating error messages if they are not .

The C programming language was developed by Dennis Ritchie at AT&T Bell Labs in 1972. It evolved from the earlier programming language B, which Ken Thompson developed in 1969-70. B itself was used as a basis for developing C, providing foundational elements for what became a general-purpose, high-level programming language originally intended for writing system programs under the Unix OS. The first version was known as K&R C, and later, the American National Standards Institute (ANSI) developed a standard version called ANSI C in the late 1980s, which included new features unavailable in earlier versions .

In the C programming environment, a compiler translates the source program, written in a high-level language, into an object program, which is a machine-readable format. In Turbo C++, the compiler is part of the IDE, and users engage it by selecting options from the menu bar. It checks for syntax errors and generates error messages, facilitating the debugging process. Compiling is an essential part of program preparation as it converts code into a format actionable by the system's processor .

C programming language includes several features that make it powerful for developing diverse types of software. Its well-defined syntax supports creating complex and well-organized code. C allows modular programming, where large tasks are divided into smaller, manageable functions. The language is also hardware-independent, enhancing software portability across different systems. C provides robust control over hardware, useful in system programming, and supports efficient code execution and resource management due to its refined compiler design. Additionally, C's small set of keywords makes it accessible and understandable, impacting its continuous use in varied development arenas .

You might also like