The document provides information about C programming language and its features. It discusses the basic structure of a C program which includes documentation, link, definition, global declaration, main function, and sub-program sections. It also describes the four steps to execute a C program: create, compile, link, and execute. Different forms of the main statement in C are discussed including main(), main(void), int main(), void main(), void main(void), and int main(void).
Oppenheimer Film Discussion for Philosophy and Film
C Programming Language Features and Structure
1. 1
C Programming Language
Group A
1. What is Programming Language? What down some salient
features of C Programming Language?
Ans: Computer Programming is simply writing down instructions for the computer
to follow. For stating the instructions, we need some language in which to state the
instructions. Unfortunately nature language such as English is insufficiently precise
for giving instructions to computers. Instead, we use special purpose languages
called programming Language. Thus programming Dan be defined as process of
writing, testing, debugging/troubleshooting and maintaining the source code of
computer programs.
Salient Features of C Programming
C is a general purpose language i.e. it can be used for any type of
programming solution.
It is a structured programming, so it provides a disciplined approach to write
the program.
It has high level constructs, which gives users the programming efficiency.
It can handle low level language, which gives the machine efficiency.
It has a rich set of built-in functions and operators that can be used to write
any complex program.
Program written in C are efficient and fast due to its variety of data types and
powerful operators.
2. What is C token? Explain the basic structure of a C program?
Ans: Individual word and punctuation marks are called C tokens. In a C program
the smallest individual units are known as C tokens. C has six types of tokens as
shown in Fig 2.
C Token
Keyword Identifier Constant String Special Symbol Operator
Fig 1: C Token.
2. 2
Basic Structure of C Program
The basic structure of C is given in Fig 2.
Documentation section
Link section
Definition
Section
Global declaration section
main() function section
{
Declaration part
Executable
}
Sub program section
function 1
function 2
…………….
Fig 2: basic Structure of C program
DocumentationSection
It is set of Computer Line
It includes Title Of Program, Author Name
Data Used Or Summary Information
Link Section
It is also called Header File Declaration Section
It Links Compiler to Link Functions From System Library
Definition Section
Defines Symbolic Constants
Eg. #define Count 10
Global DeclarationSection
Variable that are accessed byone or more functions are called Global
Variable
Global Variables are declared in this Section.
Global Variables are always Declared outside of all Functions
May Contain Function Definition
Main Function Section
User to start of actual C program.
It include two parts as declaration part and executable part.
Sub ProgramSection
It has all User-defined Functions that are called in main
User Defined Functions are generally placed immediately after main
3. 3
3. Write down the steps of executing a C program. What are the
different forms of main statements C permits?
Ans: C program executes in 4 (four steps). This is given in Fig 3.
Create
program
Compile
program
Link
program
Execute
program
Fig 3: Executing of a C Program
Creating a program
An editor like notepad or WordPad is used to create a C program. This file contains a
sourcecodewhich consists of executable code. The file should be saved as ‘*.c’
extension only.
Compiling the program
The next step is to compile the program. The codeis compiled by using compiler.
Compiler converts executable codeto binary codei.e. object code.
Linking a program to library
The object codeof a program is linked with libraries that are needed for execution of a
program. The linker is used to link the program with libraries. It creates a file with
‘*.exe’extension.
Executing the program
The final executable file is then run by dos command prompt or by any other software.
Different Forms of main() Statement
C permits different forms of main statement. The following forms are allowed:
main()
main(void)
int main()
void main()
void main(void)
int main(void)
main() and main(void)
The empty pair of parentheses main()and also the main(void) indicates that the
function has no argument.
int main()
The statement intmain()indicates that the function returns an integer value to the
operating system.
void main()
The statement void main() indicates that the function does not return any information
to the operating system.
void main(void)
The statement void main(void) indicates that the function does not return any
information to the operating system and it has no argument.
4. 4
int main (void)
The statement intmain(void) indicates that the function returns an integer value to the
operating system and it has no argument.
4. Describe the purpose of #define and #include directive. Why
should not these directive end with a semicolon?
Ans: The #define Directive
A #define is a preprocessorcompiler directive and not a statement. Therefore
#define line should not end with a semicolon. Symbolic constants are generally
written in uppercaseso that they are easily distinguished from lowercase variable
names. #define instructions are usually placed at the beginning before the main()
function. Symbolic constants are not declared in declaration section.
The #include Directive
As mentioned earlier, C programs are divided into modules or functions. Some
functions are written by users, like us and many others are srored in the C library.
Library Functions are grouped category-wise and stored in different files known as
header files. If we want to access the functions stored in the library. It is necessary
to tell the compiler about the files to be accessed.
This is achieved by using the preprocessordirective #include as follows:
#include<filename>
filenameis the name of the library file that contains the required function
definition. Preprocessordirective are placed at the beginning of a program.
5. Draw a flow chart that shows the process of compiling and
running a C program.
Ans: The process of compiling and running a C program is given in Fig 4.
5. 5
System ready
Program code Enter program
Source code
Edit source program
C compiler Compile source program
Yes
No Object code
System
library
Link with the system library
Executable object code
Input data Execute object code
Data errors Logic errors
No errors
Correct output
Srop
Fig 4: Process of Compiling And Running A C Program.
6. What is a tri-graph character? How are they useful?
Ans: Many non-English keywords do not support some special character. To
overcome this program, Table 1. ANCI C introduces the conceptof “tri-graph”
sequences to provide a way to enter certain characters that are not available in some
keyboards, each characters are known as “tri-graph” character. Table 2 shows the
trigraph character.
Syntax errors?
Logic & data
error
6. 6
Letters Digits
Uppercase A….Z All decimal digits 0….9
Lowercase a….z
Special Characters
, comma & ampersand
. period ^ caret
; semicolon * asterisk
: colon - minus
? question mark + plus sign
‘ apostrophe < opening angle bracket(or less than
sign)
“ quotation mark > closing angle bracket(or greater than
sign)
!exclamation mark ( left parenthesis
/ slash ) right parenthesis
backslash [ left bracket
~ tilde ] right bracket
_ under score { left brace
$ dollar sign } right brace
White Spaces
Blank space
Horizontal tab
Carriage return
New line
Table 1: C Character Set
Table 2: ANSI C Tri-graph Sequences
Tri-graph sequence Translation
??= # number
??( [ left bracket
??) ] right bracket
??< { left brace
??> } right brace
??! | vertical bar
??/ back slash
?? ^ caret
??- ~ tilde
6. What are the rules for declaring identifiers?
Ans: An identifier is a name. It can be the name of a variable, function, a structure
or union, a member of a struct, union or enum, a typedef name, a macro name or a
macro variable.
Example:
Sum, toal_marks,sub1, sub2.
7. 7
Rules for Declaring an Identifier
Identifier name must be a sequence of letter and digits and must begin with a
letter.
The underscorecharacter (‘_’) is considered as letter.
Names shouldn’t be a keyword (such as int, float, if, break, for etc).
Both upper-case letter and lower-case letter characters are allowed.
However, they’re not interchangeable.
No identifier may be keyword.
No special characters, such as semicolon, period, blank space, slash or
comma are permitted.