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

Programming Language (C) : Nalini Vasudevan Columbia University

This document provides an overview of an introductory C programming course taught by Nalini Vasudevan at Columbia University in Fall 2009. The course will cover basic C programming concepts like variables, data types, operators, input/output functions, and control structures. It will be taught over 9 weeks and graded based on homework assignments and a final project.

Uploaded by

Lenny Biamby
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Programming Language (C) : Nalini Vasudevan Columbia University

This document provides an overview of an introductory C programming course taught by Nalini Vasudevan at Columbia University in Fall 2009. The course will cover basic C programming concepts like variables, data types, operators, input/output functions, and control structures. It will be taught over 9 weeks and graded based on homework assignments and a final project.

Uploaded by

Lenny Biamby
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

ProgrammingLanguage

(C)
NaliniVasudevan
ColumbiaUniversity

WhyCProgramming?

WhyCProgramming?
Provideslowlevelaccesstomemory
Provideslanguageconstructsthatmap
efficientlytomachineinstructions

Aboutthecourse
Instructor: NaliniVasudevan
Email: [email protected]
OfficeHours:

467CSB(OpenDoor)

CourseTime: Wednesdays,11amto1pm
CourseLocation:

1127Mudd

Credits:1

CourseDuration:

9/9/09to10/14/09

CourseWebsite:

http://www.cs.columbia.edu/~naliniv/2009fall3101.php

Grading

Homeworks:60%

Project:40%

ClassParticipation:Extracredit(Not
applicableforCVNstudents)
NoExam

Textbook

Miscellaneous
Questionnaire
Notes

Let'saddtwonumbers

Addingtwonumbers

x=5;
y=10;

Addingtwonumbers

x=5;
y=10;
z=x+y;

Addingtwonumbers

intx,y,z;
x=5;
y=10;
z=x+y;

Addingtwonumbers

intx,y,z;
x=5;
y=10;
z=x+y;
printf("Thesumis%d",z);

Addingtwonumbers

main()
{
intx,y,z;
x=5;
y=10;
z=x+y;
printf("Thesumis%d",z);
}

Addingtwonumbers
#include<stdio.h>
main()
{
intx,y,z;
x=5;
y=10;
z=x+y;
printf("Thesumis%d",z);
}

Addingtwonumbers
#include<stdio.h>/*Headerfile*/
main()/*Themainfunction*/
{
intx,y,z; /*Variable
Declaration*/
x=5;
y=10;
z=x+y;
printf("Thesumis%d",z);
}

ProgramCompilationandExecution

Tocompile

gccoaddadd.c

oplacetheoutputinfileadd

addistheexecutablefile

Torun

./add

Cstatements

Examples

x=y+3;/*Assignment*/

printf(hello);/*Functioncall*/

intx;/*VariableDeclaration*/

Endwithasemicolon

Variables

Holdvalues,mustbedeclaredbeforeuse

Example

a=3+4;/*aisavariable*/

Types

inta; /*Integervalueslike1,
44,26*/

chara; /*Characterslikea,b,$,
#,\n*/

floata; /*Decimalfractionslike

0.1,2.3*/

int

4bytes(compilerdependent)

Atotalof2^32values

2^31to2^311

Variants

shortinta;/*2bytes*/

longinta; /*8bytes*/

unsignedinta; /*Onlypositive
numbers*/

0to2^321

char

Example

1byte

var='x';
Atotalof2^8values

ASCIIrepresentation

Asciivalueof'a'is97

Asciivalueof'b'is98

float

Floatingdecimalpoint

Example

floata;
a=2.54;

4bytes

IEEEformat

3.4e^38to3.4e^38

double

Twicethememoryasfloat

8bytes(generally)

sizeof
#include<stdio.h>/*Headerfile*/
main()/*Themainfunction*/
{
intx; /*VariableDeclaration*/
printf("xis%dbytes",sizeof(x));
}

Casting

Wecancastavariabletoadifferenttypethanits
actualtype

intx;
floaty;
x=3;
y=(float)x;/*Explicitcasting*/
y=x; /*Implicitcasting*/

printf

Example

printf(Thesumof%dand%dis
%d,x,y,z);

Ouput

Thesumof5and10is15

Placeholders

%d int

%f float

%c char

printf

Example

printf(Hello!);
printf(Thesumof%dand%dis
%d,x,y,z);

Ouput

Hello!Thesumof5and10is15

printf

Example

printf(Hello!\n);
printf(Thesumof%dand%dis
%d,x,y,z);

Ouput

Hello!
Thesumof5and10is15

Addingtwonumbers
#include<stdio.h>/*Headerfile*/
main()/*Themainfunction*/
{
intx,y,z; /*Variable
Declaration*/
x=5;
y=10;
z=x+y;
printf("Thesumis%d",z);
}

scanf
#include<stdio.h>/*Headerfile*/
main()/*Themainfunction*/
{
intx,y,z; /*VariableDeclaration*/
printf(Enterx:);
scanf(%d,&x); /*Waitforinput*/
printf(Entery:);
scanf(%d,&y);/*Waitforinput*/
z=x+y;
printf("Thesumis%d",z);
}

You might also like