0% found this document useful (0 votes)
23 views10 pages

Day 1

This document provides an introduction to the C programming language. It covers key topics such as C's history, program structure, header files, the main function, writing a first program, running a C program, comments in C, standard headers, and the printf function. The document breaks down C programming concepts into easy to understand sections and provides examples to illustrate each concept.

Uploaded by

Ashwin Tandel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views10 pages

Day 1

This document provides an introduction to the C programming language. It covers key topics such as C's history, program structure, header files, the main function, writing a first program, running a C program, comments in C, standard headers, and the printf function. The document breaks down C programming concepts into easy to understand sections and provides examples to illustrate each concept.

Uploaded by

Ashwin Tandel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

C Programming

Day 1
Introduction
• C is developed by Dennis Ritchie
• C is a structured programming language
• C supports functions that enables easy
maintainability of code, by breaking large file
into smaller modules
• Comments in C provides easy readability
• C is a powerful language
Program structure
A sample C Program

#include<stdio.h>
int main()
{
--other statements
}
Header files
• The files that are specified in the include
section is called as header file
• These are precompiled files that has some
functions defined in them
• We can call those functions in our program by
supplying parameters
• Header file is given an extension .h
• C Source file is given an extension .c
Main function
• This is the entry point of a program
• When a file is executed, the start point is the
main function
• From main function the flow goes as per the
programmers choice.
• There may or may not be other functions
written by user in a program
• Main function is compulsory for any c program
Writing the first program
#include<stdio.h>
int main()
{
printf(“Hello”);
return 0;
}

• This program prints Hello on the screen when we


execute it
Running a C Program
• Type a program
• Save it
• Compile the program – This will generate an exe file
(executable)
• Run the program (Actually the exe created out of
compilation will run and not the .c file)
• In different compiler we have different option for
compiling and running. We give only the concepts.
Comments in C
• Single line comment
– // (double slash)
– Termination of comment is by pressing enter key
• Multi line comment
/*….
…….*/
This can span over to multiple lines
Standard Headers you should know about:

– stdio.h – file and console (also a file) IO: perror, printf,


open, close, read, write, scanf, etc.
– stdlib.h - common utility functions: malloc, calloc,
strtol, atoi, etc
– string.h - string and byte manipulation: strlen, strcpy,
strcat, memcpy, memset, etc.
– ctype.h – character types: isalnum, isprint,
isupport, tolower, etc.
– errno.h – defines errno used for reporting system errors
– math.h – math functions: ceil, exp, floor, sqrt, etc.
– signal.h – signal handling facility: raise, signal, etc
– stdint.h – standard integer: intN_t, uintN_t, etc
– time.h – time related facility: asctime, clock, time_t,
etc.
The printf() function
printf( "Original input : %s\n", input );
• printf() is a library function declared in <stdio.h>
• Syntax: printf( FormatString, Expr, Expr...)
– FormatString: String of text to print
– Exprs: Values to print
– FormatString has placeholders to show where to put the
values (note: #placeholders should match #Exprs)
– Placeholders: %s (print as string), %c (print as char),
%d (print as integer),
%f (print as floating-point)
– \n indicates a newline character

CS 3090: Safety Critical Programming in C 10

You might also like