



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This document offers a comprehensive comparison of c and c++, highlighting key differences in syntax, features, and applications. it delves into data types, memory management, object-oriented programming concepts supported by c++, and explores real-world applications of both languages in operating systems, embedded systems, and more. Valuable for students learning programming languages and those seeking to understand the evolution and distinctions between c and its object-oriented extension, c++. it provides a solid foundation for further study in computer science.
Typology: Lecture notes
1 / 35
This page cannot be seen from the preview
Don't miss anything!
Enlisted below are the major set of differences between the programming languages, C and C++. Sl.No Basis Of Distinction
Nature Of Language C is a structural or procedural type of programming language (POP). C++ is an object-oriented programming(OOP) language and supports Polymorphism, Abstract Data Types, Encapsulation, among others. Even though C++ derives basic syntax from C, it cannot be classified as a structural or a procedural language. 2 Point Of Emphasis C lays emphasis on the steps or procedures that are followed to solve a problem. C++ emphasizes the objects and not the steps or procedures. It has higher abstraction level. 3 Compatibility With Overloading C does not support function overloading. C++ supports function overloading, implying that one can have name of functions with varying parameters. 4 Data Types C does not provide String data types. C++ provides String data types. 5 Compatibility With Exception Handling C does not support Exception Handling directly. It can be done through some other functions. C++ supports Exception Exception. Handling can be done through try & catch block. 6 Compatibility With Generic Programming C is not compatible C++ is compatible with generic programming
Pointers And References C supports only Pointers C++ supports both pointers and references. 8 Data Security In C programming language, the data is unsecured. Data is hidden in C++ and is not accessible to external functions. Hence, is more secure 9 Approach C follows the top- down approach. C++ follows the bottom-up approach. 10 Functions For Standard Input And Output scanf and printf cin and cout 11 Time Of Defining Variables In C, variable has to be defined at the beginning, in the function. Variable can be defined anywhere in the function. (^12) Namespace Absent Present 13 Division Of Programs The programs in C language are divided into modules and functions. The programs are divided into classes and functions in the C++ programming language. 14 File Extension .c .cpp 15 Function And Operator Overloading Absent Present 16 Mapping Mapping between function and data is Mapping between function and data can be done easily using ‘Objects’.
C++ is used by programmers to create computer software. It is used to create general systems software , drivers for various computer devices, software for servers and software for specific applications and also widely used in the creation of video games. C++ is used by many programmers of different types and coming from different fields. C++ is mostly used to write device driver programs , system software and applications that depend on direct hardware manipulation under real time constraints. It is also used to teach the basics of object oriented features because it is simple and is also used in the fields of research. Also, many primary user interfaces and system files of Windows and Macintosh are written using C++. So, C++ is really a popular, strong and frequently used programming language of this modern programming era.
Example 1: Hello World Program #include
4. Embedded Systems: Various features of C including direct access to machine level hardware APIs, presence of C compilers, deterministic resource use and dynamic memory allocation make C language an optimum choice for scripting applications and drivers of embedded systems. 5. Graphics and Games: C language has been used in the development of a variety of graphics and gaming applications, such as chess, bouncing ball, archery etc. **Real-World Applications of C++
C++ and C have been used for scripting MySQL, one of the most popular database management software. The software forms the backbone of a variety of database-based enterprises, such as Google, Wikipedia, Yahoo and YouTube etc.
6. Operating Systems: C++ forms an integral part of many of the prevalent operating systems including Apple’s OS X and various versions of Microsoft Windows, and the erstwhile Symbian mobile OS. 7. Enterprise Software: C++ finds a purpose in banking and trading enterprise applications, such as those deployed by Bloomberg and Reuters. It is also used in development of advanced software, such as flight simulators and radar processing. 8. Medical and Engineering Applications: Many advanced medical equipments, such as MRI machines, use C++ language for scripting their software. It is also part of engineering applications, such as high-end CAD/CAM systems. 9. Compilers: A host of compilers including Apple C++, Bloodshed Dev-C++, Clang C++ and MINGW make use of C++ language. C and its successor C++ are leveraged for diverse software and platform development requirements, from operating systems to graphic designing applications.
cout << "Programming is" << endl; cout << "fun!";
C++ Tokens are the smallest individual units of a program. Following are the C++ tokens : (most of c++ tokens are basically similar to the C tokens) Keywords Identifiers Constants Variables Operators Strings Keywords Keywords is reserved words which have fixed meaning and its meaning cannot be changed. Identifiers
Identifiers refers to the name of variables, functions, arrays, classes, etc. created by the user. Identifiers are the fundamental requirement of any language. Identifier naming conventions Only alphabetic characters, digits and underscores are permitted. First letter must be an alphabet or underscore (_). Identifiers are case sensitive. Reserved keywords cannot be used as an identifier's name. Constants Constants refers to fixed values that do not change during the execution of a program. Declaration of a constant : const [data_type] [constant_name]=[value]; Variable A variable is a meaningful name of data storage location in computer memory. When using a variable you refer to memory address of computer. We know that in C, all variables must be declared before they are used, this is true with C++. The main difference in C and C++ with regards to the place of their declaration in the program... C requires all the variables to be defined in the beginning of scope. C++ allows the declaration of a variable anywhere in the scope, this means that a variable can be declared right at the place of its first use. Syntax to declare a variable : [data_type] [variable_name]; Consider the example #include <iostream.h> int main()
++ Increment −− Decrement
Operator Description == Is equal to != Is not equal to
Greater than < Less than = Greater than or equal to <= Less than or equal to
Operator Description && (^) And operator. Performs a logical conjunction on two expressions. (if both expressions evaluate to True, result is True. If either expression evaluates to False, result is False) || Or operator. Performs a logical disjunction on two expressions. (if either or both expressions evaluate to True, result is True) ! (^) Not operator. Performs logical negation on an expression.
Operator Description << Binary Left Shift Operator
Binary Right Shift Operator
~ Binary Ones Complement Operator & Binary AND Operator ^ Binary XOR Operator | Binary OR Operator
Operator Description = Assign += Increments, then assigns
= Right shift and assigns &= Bitwise AND assigns ^= Bitwise exclusive OR and assigns |= Bitwise inclusive OR and assigns
Operator Description , Comma operator sizeof() Returns the size of an memory location. & Returns the address of an memory location.
Data Types available in C++:
Data Type (Keywords) Description Size Typical Range char Any single character. It may include a letter, a digit, a punctuation mark, or a space. 1 byte - 128 to 127 or 0 to 255 signed char Signed character. 1 byte - 128 to 127 unsigned char Unsigned character. 1 byte 0 to 255 w char_t Wide character. 2 or 4 bytes 1 wide character
Data Type (Keywords) Description Size Typical Range int Integer. 4 bytes - 2147483648 to 2147483647 signed int Signed integer. Values may be negative, positive, or zero. 4 bytes - 2147483648 to 2147483647 unsigned int Unsigned integer. Values are always positive or zero. Never negative. 4 bytes 0 to 4294967295 short Short integer. 2 bytes - 32768 to 32767 signed short Signed short integer. Values may be negative, positive, or zero. 2 bytes - 32768 to 32767 unsigned short Unsigned short integer. Values are always positive or zero. Never negative. 2 bytes 0 to 65535 long Long integer. 4 bytes - 2147483648 to 2147483647 signed long Signed long integer. Values may be negative, positive, or zero. 4 bytes - 2147483648 to 2147483647 unsigned long Unsigned long integer. Values are always positive or zero. Never negative. 4 bytes 0 to 4294967295 Floating-point Data Types Data Type (Keywords) Description Size Typical Range float Floating point number. There is no fixed number of digits before or after the decimal point. 4 bytes +/- 3.4e +/- 38 (~7 digits) double Double precision floating point number. More accurate compared to float. 8 bytes +/- 1.7e +/- 308 (~15 digits) long double Long double precision floating point number. 8 bytes +/- 1.7e +/- 308 (~15 digits) Boolean Data Type Data Type Description Size Typical
Example: The cin Object Reads Different Data Types
Definitions: