Programming 1 (C/C++)
Programming 1 (C/C++)
Programming 1 (C/C++)
Programming 1
Turbo C was an Integrated Development Environment and compiler for the C programming
language from Borland. It was first introduced in 1987 and was noted for its integrated development environment,
small size, extremely fast compile speed, comprehensive manuals and low price.
In May 1990, Borland replaced Turbo C with Turbo C++. In 2006, Borland reintroduced the Turbo moniker.
What is C++?
Characteristics of C
void functions
Functions returning struct or union types instead of pointers
Assignments enabled for struct data types
const qualifier to make an object read-only
Enumerated types
Creation of tool to avoid the inherent problems of the language
Soon C became powerful enough to have the UNIX Kernel (written in an assembly language) re-written making it one
of the first OS Kernels written in a language apart from the assembly languages.
Characteristics of C++
Programming 1
C++ is designed to be a statically typed, general-purpose language that is as efficient and portable as C
C++ is designed to directly and comprehensively support multiple programming styles (procedural
programming, data abstraction, object-oriented programming, and generic programming)
C++ is designed to give the programmer choice, even if this makes it possible for the programmer to
choose incorrectly
C++ is designed to be as compatible with C as possible, therefore providing a smooth transition from C
C++ avoids features that are platform specific or not general purpose
C++ does not incur overhead for features that are not used
C++ is designed to function without a sophisticated programming environment
Polymorphism, one of the prominent qualities of C++, enables many implementations with a single
interphase and for objects to act according to circumstances. C++ supports both static (compile-time) and dynamic
(run-time) polymorphisms. Compile-time polymorphism does not allow for certain run-time decisions, while run-time
polymorphism typically incurs a performance penalty. C++, though considered a superset of C, there exist a few
differences causing some valid C codes to be invalid in C++ or to behave differently in C++. Issues like the C++
defining new keywords namely new & class, that are used as identifiers in C. C and C++ codes can be intermixed by
declaring any C code that is to be called from/used in C++ with C linkage & by placing it within an extern "C" { /* C
code */ } block.
Structure of a C program
Every C program consists of one or more functions. A function is nothing but a group or sequence of C
statements that are executed together. Each C program function performs a specific task. The ‘ main()’ function is the
most important function and must be present in every C program. The execution of a C program begins in
the main() function.
The figure below shows the structure of a C program.
main() function1() function2()
{ { {
statement1; statement1; statement1;
statement2; statement2; statement2;
……; ……..; ……;
……; ……..; ……;
} } }
Programmers are free to name C program functions (except the main() function).
view source
print?
01 // File: struct-test.cpp
02 //
03 // This example shows the use of a structure in C++ and how it behaves much
04 // like a class including the use of a contructor yet maintains the useability
05 // of a regular C structure.
06
07 #include <iostream>
Programming 1
08 #include <string>
09
10 using namespace std;
11
12 main()
13 {
14 struct DataElement {
15 string SVal;
16 int iVal;
17 bool hasData;
18
20 {
21 iVal=-1;
22 hasData=0;
23 }
24 } *RealData;
25
26 RealData = new DataElement [ 5 ];
27
28 // Assignment
29 RealData[0].SVal = "Value loaded into first structure element.";
31
37
39
40 }
Compile: g++ struct-test.cpp
Programming 1
[Potential Pitfall]: In Red Hat Linux versions 7.x one could omit the "using namespace std;" statement. Use of this
statement is good programming practice and is required in Red Hat 8.0.
[Potential Pitfall]: Red Hat 8.0 requires the reference to "#include <fstream>". Red Hat versions 7.x used "#include
<fstream.h>".
Output: ./a.out
HISTORY of Turbo C
In 1978 Brian Kernighan and Dennis Ritchie wrote the famous book called THE C PROGRAMMING LANGUAGE.
C is often called a Middle Level Language but has a functionalism of a high-level language and assembly language. C
has only 32 keywords (27 from Kernighan and Ritchie standard and 5 added by the ANSI Standardization committee).
Programming is a series of individual instructions to the computer that collectively perform a meaningful task. It is the
act of writing or coding computer instructions.
Programmer is the one who write the computer program and the first lady programmer is Lady Augusta "Ada" Byron.
Translator is use to transform the source code into a machine language that the computer can understand.
Linker is use to adjust the translated source file so that the program will run. Linking is usually distinct from the
compiling process on a machine running MS-DOS.
History of C++
C++ was developed significantly after its first release. 1 In particular, "ARM C++" added exceptions and
templates, and ISO C++ added RTTI, namespaces, and a standard library. 1
C++ was designed for the UNIX system environment. With C++ programmers could improve the quality of code they
produced and reusable code was easier to write.
Bjarne Stroustrup had studied in the doctoral program at the Computing Laboratory at Cambridge University prior to
joining Bell Labs. Now, Bell Labs no longer has that name since part of Bell Labs became AT&T Labs. The other half
became Lucent Bell labs.
Prior to C++, C was a programming language developed at Bell Labs circa 1969-1973. The UNIX operating
system was also being developed at Bell Labs at the same time. C was originally developed for and implemented on the
UNIX operating system, on a PDP-11 computer by Dennis Ritchie. He extended the B language by adding types in
Programming 1
1971. He called this NB for New B. Ritchie credited some of his inspiration from theAlgol68 language. Ritchie
restructured the language and rewrote the compiler and gave his new language the name "C" in 1972. 90% of UNIX
was then written in C. The committee that wrote the 1989 ANSI Standard for C had started work on the C Standard
project in 1983 after having been established by ANSI in that year. There were quite a number of versions of C at that
time and a new Standard was necessary.
C is portable, not tied to any particular hardware or operating system. C combines the elements of high-level
languages with the functionality of assembly language and has occasionally been referred to as a middle-level computer
language. C makes it easy to adapt software for one type of computer to another.
C was a direct descendant of the language B. The language B was developed by Ken Thompson in 1970 for the new
UNIX OS. B was a descendant of the language BCPL designed by Martin Richards, a Cambridge University student
visiting MIT.1