C Language Introduction PDF
Document Details
Uploaded by Deleted User
Technological University of the Philippines, College of Industrial Education
Ms. Rica Angela Sumo
Tags
Summary
This document provides a basic introduction to the C programming language, covering key concepts such as header files, the main method, statements, and data types. It's geared toward an undergraduate-level audience at the Technological University of the Philippines.
Full Transcript
introduction to c language Prepared by Ms. Rica Angela Sumo C Language C is a general-purpose, high-level language that was originally developed by Dennis M. Introduction Background of the Study RitchieGap Research to develop the UNIX operating...
introduction to c language Prepared by Ms. Rica Angela Sumo C Language C is a general-purpose, high-level language that was originally developed by Dennis M. Introduction Background of the Study RitchieGap Research to develop the UNIX operating system Statement of the at Bell Labs. Problem Phase 1: Qualitative Phase C 2: Phase has now become a widely used Quantitative Phase professional Phase 3: Design Based language for various reasons: Scope andEasy to learn Limitations Significance of the Study Structured language It produces efficient programs It can handle low-level activities It can be compiled on a variety of computer platforms Difference Difference between C and C++ C++ was developed as an extension of C, and both languages have almost the same syntax The main difference between C and C++ is that C++ support classes and objects, while C does not 1. Header Files Inclusion – Line 1 [#include ] The first and foremost component is the inclusion of the Header files in a C program. A header file is a file with extension.h which contains C function declarations and macro definitions to be shared between several source files. All lines that start with # are processed by a preprocessor which is a program invoked by the compiler. In the example, the preprocessor copies the preprocessed code of stdio.h to our file. The.h files are called header files in C. Some of the C Header files: stddef.h – Defines several useful types and macros. stdint.h – Defines exact width integer types. stdio.h – Defines core input and output functions stdlib.h – Defines numeric conversion functions, pseudo-random number generator, and memory allocation string.h – Defines string handling functions math.h – Defines common mathematical functions 2. Main Method Declaration – Line 2 [int main()] The next part of a C program is to declare the main() function. It is the entry point of a C program and the execution typically begins with the first line of the main(). The empty brackets indicate that the main doesn’t take any parameter The int that was written before the main indicates the return type of main(). The value returned by the main indicates the status of program termination. 3. Body of Main Method – Line 3 to Line 6 [enclosed in {}] The body of a function in the C program refers to statements that are a part of that function. It can be anything like manipulations, searching, sorting, printing, etc. A pair of curly brackets define the body of a function. All functions must start and end with curly brackets. 4. Statement – Line 4 [printf(“Hello World”);] Statements are the instructions given to the compiler. In C, a statement is always terminated by a semicolon (;). In this particular case, we use printf() function to instruct the compiler to display “Hello World” text on the screen. 5. Return Statement – Line 5 [return 0;] The return statement refers to the return values from a function. This return statement and return value depend upon the return type of the function. The return statement in our program returns the value from main(). The returned value may be used by an operating system to know the termination status of your program. The value 0 typically means successful termination. 1. Header Files Inclusion – Line 1 [#include ] The first and foremost component is the inclusion of the Header files in a C program. A header file is a file with extension.h which contains C function declarations and macro definitions to be shared between several source files. All lines that start with # are processed by a preprocessor which is a program invoked by the compiler. Variables and Data Types Variables: Containers for storing data. int: Integer numbers float: Floating-point numbers char: Single characters double: Double-precision floating-point numbers Input and Output Input Function: Output Function: scanf: Reads input from the printf: Prints output to the user. console. Functions in C Functions are reusable blocks of code. Arrays in C An array is a collection of elements of the same data type. THANK YOU