C-PROGRAMMING LANGUAGE

Unformatted text preview:

1 C PROGRAMMING LANGUAGE SIMPLE NOTES BY S ANTONY ALEX FOR MORE NOTES CONTACT antonyalex476 gmail com TABLE OF CONTENTS S NO TOPICS PG NO INTRODUCTION TO C PROGRAMMING VARIABLES AND DATA TYPES FUNCTIONS IN C PROGRAMMING OPERATIONS IN C PROGRAMMING OPERATORS IN C PROGRAMMING VARIABLES IN C PROGRAMMING DATA TYPES IN C PROGRAMMING MODIFIERS IN C PROGRAMMING CONSTANTS IN C PROGRAMMING BRANCHING STATEMENTS LOOPING STATEMENTS LOOP CONTROL STATEMENTS JUMP STATEMENTS STRINGS IN C PROGRAMMING STRING HANDLING POINTERS IN C PROGRAMMING STRUCTURE AND UNION DIFFERENCE B W STRUCTURE UNION FILES IN C PROGRAMMING FILE MANAGEMENT IN C PROGRAMMING 3 4 6 14 15 22 25 28 30 34 38 40 43 46 51 56 61 66 67 71 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 C PROGRAMMING LANGUAGE C programming is a powerful and versatile programming language that forms the basis for many other programming languages Here are some basics to get you started The classic Hello World program is a simple way to start learning any programming language 3 Hello World Program Example include stdio h printf Hello World n int main return 0 Comments This is a multiline comment This is a single line comment This program uses the printf function to display the text Hello World on the console You can use comments to add explanations to your code Comments in C begin with and end with for multiline comments or use for single line comments C is a statically typed language meaning you need to declare the type of a variable before using it Variables and Data Types Example include stdio h int main Variable declaration int age 25 float height 5 9 char grade A Display variables printf Age d n age printf Height f n height printf Grade c n grade return 0 Input and Output You can use scanf for input and printf for output Example include stdio h int main 4 C supports common control flow statements like if else while for Input int num printf Enter a number scanf d num Output printf You entered d n num return 0 Control Flow Example include stdio h int main int num 10 if else statement if num 0 printf Positive number n printf Non positive number n else while loop 5 int i 0 while i 5 printf d i i printf n for loop for int j 0 j 5 j printf d j printf n return 0 Functions These are just the basics to get you started with C programming As you delve deeper you ll encounter more advanced concepts like functions arrays pointers and structures Practice is crucial in mastering any programming language so try to solve small problems and gradually move to more complex projects Certainly Functions and operations are fundamental aspects of C programming that allow you to organize code into reusable blocks and perform various tasks Here s an overview of basic functions and operations in C 6 Function Declaration and Definition Functions in C are declared and defined using the following syntax Function declaration returnType functionName parameterType1 parameterName1 parameterType2 parameterName2 returnType functionName parameterType1 parameterName1 parameterType2 parameterName2 return returnValue optional return statement Function definition Function body Statements Example include stdio h Function declaration int add int a int b int main Function call int result add 5 3 printf Sum d n result 7 Function Parameters and Return Values Functions can take parameters inputs and return values outputs Parameters are specified in the function declaration and the return statement is used to send a value back to the calling code return 0 Function definition int add int a int b return a b Example include stdio h int multiply int x int y return x y int main int result multiply 4 7 printf Product d n result return 0 8 Function Prototypes Function prototypes provide a declaration of a function before its actual implementation This allows you to use functions before they are defined in the code Example include stdio h Function prototype int subtract int a int b int main int result subtract 10 4 printf Difference d n result return 0 Function definition int subtract int a int b return a b Standard Library Functions These functions are provided by the C standard library and are available for use in any C program Examples include functions like printf scanf malloc free strcpy and many more They are typically included by including the appropriate header files 9 User Defined Functions These are functions created by the programmer to perform specific tasks They can be divided into two main types Void Functions Functions that do not return any value Example include stdio h printf Hello World n int main return 0 include stdio h void greet printf Hello World n int main greet return 0 10 Functions with Return Values Functions that return a value of a specific data type include stdio h int add int a int b return a b int main int result add 5 3 printf Sum d n result return 0 Recursive Functions include stdio h int factorial int n if n 1 return 1 else return n factorial n 1 11 A function that calls itself either directly or indirectly Recursive functions are useful for solving problems that can be broken down into smaller similar sub problems These are functions defined in external libraries that can be linked to a C program For example the math library provides functions like sqrt sin cos etc To use these functions you need to include the appropriate header file and link the corresponding library int main int result factorial 5 printf Factorial d n result return 0 Library Functions Example include stdio h include math h int main return 0 double squareRoot sqrt 25 0 printf Square Root f n squareRoot Function Pointers C allows the use of function pointers which are variables that store addresses of functions This feature is particularly useful in scenarios like callback functions or creating flexible function interfaces 12 Example include stdio h int add int a int b return a b int subtract int a int b return a b int main int operation int int Function pointer declaration operation add Pointing to the add function printf Sum d n operation 5 3 operation subtract Pointing to the subtract function printf Difference d n operation 10 4 return 0 These are some of the common types of functions in C programming Understanding and using these various types of functions will help you write modular and maintainable code 13 Basic arithmetic operations include addition subtraction multiplication division and modulus Operations Arithmetic Operations Example include stdio h int main int a 10 b 3 printf Sum


View Full Document

C-PROGRAMMING LANGUAGE

Download C-PROGRAMMING LANGUAGE
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view C-PROGRAMMING LANGUAGE and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view C-PROGRAMMING LANGUAGE and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?