0% found this document useful (0 votes)
19 views

Presentation On Components of Programming-1

1. The document compares the basic structure of C and C++ programs. Both include necessary header files, have an int main() function that returns 0, and use curly braces to define the scope of main. 2. C programs can use printf() to print output, while C++ uses std::cout with << operators. Both print "Hello World!" as an example. 3. Comments (denoted with // and /* */) and return 0 are also described as common elements of the basic program structure.

Uploaded by

aimenshahzad555
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Presentation On Components of Programming-1

1. The document compares the basic structure of C and C++ programs. Both include necessary header files, have an int main() function that returns 0, and use curly braces to define the scope of main. 2. C programs can use printf() to print output, while C++ uses std::cout with << operators. Both print "Hello World!" as an example. 3. Comments (denoted with // and /* */) and return 0 are also described as common elements of the basic program structure.

Uploaded by

aimenshahzad555
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRESENTATION:

ICT(Information and
communication
technology)

C Program Structure:
cCopy code
#include <stdio.h> // Incl

ude necessary libraries int main() {

// Coprintf
( "Hello, World!" ); // Print a message to the console return 0 ; // Indicate successful execution }

C++ Program Structure:


cppCopy code
#include <iostream> // Include necessary libraries int main() { // Code inside the main function std::cout <<
"Hello, World!" << std::endl; // Print a message to the console return 0 ; // Indicate successful execution }

Breakdown:

1. #include <header_file>: This line is a preprocessor directive that tells the


compiler to include a specific library. For example, #include <stdio.h> in C
includes the standard input-output library, and #include <iostream> in C++
includes the input-output stream library.
2. int main(): mai
is a special function where the program starts its execution. It returns an
integer value (usually 0) to the operating system, indicating the successful
execution of the program. The execution of the program starts from the
beginning of the main function.

{ ... }:

3. Curly braces define the scope of the main function. All the code inside the
curly braces belongs to the main function.
4. // ... or / ... /: These are comments in the code. Comments are ignored by the
compiler and are for human readers to understand the code better. // is used
for single-line comments, and /* */ is used for multi-line comments
.
5. printf("Hello, World!"); (in C) or std::cout << "Hello, World!" << std::endl;
(in C++): These are examples of output statements. They print "Hello, World!"
to the console.

6. return 0;: Indicates the end of the main function and typically signifies
successful execution. The value 0 is returned to the operating system.

This is the basic structure of a C or C++ program. Of course, real-world


programs are much more complex and can include additional functions,
control structures, and libraries as needed for the specific task the program is
designed for.

You might also like