UNIT -5 FUNCTIONS AND POINTERS

Size: px
Start display at page:

Download "UNIT -5 FUNCTIONS AND POINTERS"

Transcription

1 1. FUNCTIONS: UNIT -5 FUNCTIONS AND POINTERS C language programs are highly dependent on functions. Program always starts with user defined main () function. C supports two types of functions. They are, Library functions User defined functions Library functions: It is predefined set of functions. User can see the function but cannot change or modify them. User defined functions: Functions defined by the user according to the requirement. User can understand the internal workings of the functions. a) Definition of function: A function is a self-contained block or a sub program of one or more statements that performs a special task when called. Why use functions: If we want to perform a task repetitively then it is not necessary to re-write the particular block of the program. The function defined can be used for any number of times to perform the task. Using functions, large programs can be reduced to smaller ones.

2 It is easy to debug and find out the errors in it. It increases readability. How function works: o o o o o Once a function is defined and called, it takes some data from the calling function and returns a value to the called function. If a function is called, control passes to called function and working of the calling function is stopped. When the execution of the called function is completed, control returns back to the calling function and execute the next statement. The number of actual arguments and formal arguments should be same. The function operates on formal arguments and sends back the result to the calling function. return () statement performs this task. 2. DECLARATION OF FUNCTION: Syntax: function-name (argument/ parameter list) argument declaration; local variable declaration; statement1; statement2; return (value); Working of function: main ()

3 abc (x,y,z);//function call actual arguments abc (l,k,j) --- function definition formal argument return(); --return value. Actual argument: The arguments of calling function. x,y,z are actual arguments from above example. Formal argument: Arguments of called function. l,k,j are formal arguments from above example. Function name Same as variable naming Eg: sum (inta,int b); sum-user defined function int a, int b-integer variable arguments Argument parameters list:

4 variable names enclosed within parenthesis. They must be separated by comma. Function call: A compiler executes the function when a semicolon is followed by function name. Eg: main() int x=1,y=2,z; z=add(x,y); /* function call*/ printf( z=%d,z); /* function definition */ add ( a,b) return (a+b); Output: Z=3 Local variable: It is defined within the body of the function or block. Variable defined is local to that function or block only. Other function cannot access these variable. Eg:

5 value(int k,int m) int r,t; [r,t applicable to value] Global variable: It is defined outside the main() function. Many functions can use them. Eg: int b=10,c=5; main () Return value: It is the outcome of the function Result obtained by function is sent back to the calling function It returns one value per call Value returned is collectd by variable of the calling function. Return statement: Return statement can be used as in following ways, 1. return(expression); Eg:return(a+b+c); 2. Function may use one or more return.

6 3. return(&p); It returns address of the variable to the calling function. 4. return(*p); It returns the value of variable through the pointer to calling function. 5. return(sqrt (r) ); First control will evaluate sqrt(),then return the value. 6. return (float(sqrt(2.8)) Types of function: without arguments and return values with arguments but without return values with arguments and return values without arguments but with the return values. a) without arguments and return values eg:main () ab(); b) with arguments but without return values eg: main () abc(x);

7 c) with arguments and return values main() int z; z=abc(x); calling function ---- abc(y) --- return(y); called function --- d) without arguments but with the return values. main() int z; calling function ----

8 z=abc (); abc int y=5; return (y); called function Call by Value and Reference: a) Call by value: The Value of actual arguments is passed to the formal arguments and the operation is done on the formal arguments. Any change made in formal arguments does not affect the actual arguments. Eg: Program to send two integer values using call by value. #include<stdio.h> #include<conio.h> main () int x,y,change(int,int); clrscr(); printf( \n Enter values of x and y:\n );

9 scanf( %d%d,&x,&y); change(x,y); printf( \n In main() x=%d y=%d,x,y); return 0; change (int a,int b) int k; k=a; a=b; b=k; printf( \n change() x=%d y=%d,a,b); Output: Enter values of x and y:5 4 In chage () x=4 y=5 In main () x=5 y=4 b) Call by reference: Instead of passing values, addresses (reference) are passed. Function operates on addresses rather than values. Formal arguments are pointers to the actual arguments.

10 Eg: Program to send a value by reference int x,y,change(int *,int *); clrscr(); printf( \n Enter values of x and y:\n ); scanf( %d%d,&x,&y); change(&x,&y); printf( \n In main() x=%d y=%d,x,y); return 0; change (int *a,int * b) int *k; *k=*a; *a=*b; *b=*k; printf( \n change() x=%d y=%d,*a,*b); Output: Enter values of x and y:5 4 In chage () x=4 y=5 In main () x=4 y=5 Function as an Argument: We can pass a function as an argument. main()

11 int y=2,x; x=double(square(y)); printf( x=%d,x); double(m) return(m*2); square(k) return (k*k); Output x=8 Recursion: A function is called repetitively by itself is called recursion. Recursion can be used directly or indirectly. Direct recursion function calls itself till the condition is true. In indirect recursion, a function calls another function then the called function calls the calling function. Eg: #include<stdio.h> #include<process.h> int x,s;

12 main (x) s=s+x; printf( \n x=%d s=%d,x,s); if(x==5) exit(0); main(++x); Output: x=1 s=1 x=2 s=3 x=3 s=6 x=4 s=10 x=5 s=15 3. STORAGE CLASS: The area or block of the c program from where the variable can be accessed is known as the scope of variable. The area or scope of the variable depends on its storage class, that is, where and how it is declared. There are four scope variables Function File Block

13 Function prototype Storage class of a variable tells the compiler: Storage area of the variable Initial value of variable if not initialized. Scope of the variable Life of the variable, that is, how long the variable would be active in the program. Any variable declared in C can have any of the 4 storage classes. Automatic variable: Variable declared inside function without storage class name. auto External Variable: available to all function, declared outside function body. Static variable: internal (auto variable) or external variable (static global) Register variables: Variables in CPU registers instead of memory. register keyword tells the compiler that the variable list followed by it is kept on the CPU registers. If CPU fails, the variables are auto and stored in memory. 4. HANDLING OF CHARACTER STRINGS: A string is a sequence of characters that is treated as a single data item. 1. Declaring and Initializing String Variables: C does not support strings as a data type. General form of declaration of a string variable is char string_ name [SIZE]; SIZE-> number of characters Eg: char city[10];

14 char city[9]= NEW YORK ; char city[9]= N, E, W, Y, O, R, K, \0 ; char string[]= G, O, O, D, \0 ; char string[10]= GOOD ; G O O D \0 \0 \0 \0 \0 \0 2. Reading strings from terminal: a. Using scanf function: char address[10]; scanf( %s,address); b. Using getchar function: char ch; ch=getchar(); c. Using gets function Eg; gets(str); char line[80]; gets(line); printf( %s,line); 3. Writing strings to terminal: a.using printf function printf( %s,name); b. using putchar function char ch= A ; putchar (ch);

15 c.using puts function puts(str); 4. String handling functions: We cannot assign one string to another directly,we cannot join two strings together by simple arithmetic addition. a. String manipulation functions: strcat () --- concatenate two strings strcmp() --- compares to strings strcpy() ---- copies one string over another. strlen()----- finds the length of a string i. strcat() It joins two strings together. strcat( string1,string2); ii. strcmp() It compares two strings identified by the arguments and has a value of o if they are equal.if they are not equal,it has the numeric difference between the first non matching characters in the strings. strcmp(string1,string2); Eg: strcmp( their, there ); It will return -9(ASCII value of(i-r))

16 iii. strcpy() It is like assignment operator. strcpy(string1,string2); Eg: strcpy(city, DELHI ); It will assign DELHI to city. iv. strlen() It counts and returns the number of characters in a string. n=strlen(string); n=strlen( Newyork ); here n is an integer. b. Other string functions: a. strncpy () It copies only the left most n charcters of the source string to target string variable. Eg: strncpy(s1,s2,5); It copies first 5 characters of source s2 into target s1. b. strncmp() strncmp(s1,s2,n); Compares left-most n characters of s1 to s2 and return 0if they are equal Negative number,if s1 sub string is less than s2.

17 Positive number, otherwise. c. strncat() strncat(s1,s2,n); Concatenate left most n characters of s2 to end of s1. B A L A \0 Eg: s1 G U R U S A M Y \0 s2 After strncat(s1,s2,4) s1: B A L A G U R U \0 d. strstr() It is used to locate a substring in string. strstr(s1,s2); Function strstr search s1 to see whether s2 is contained in s1. If yes,it returns the position of 1 st occurrence of substring. Else,NULL. e. strchr and strrchr These functions determine the existence of a character in a string.

18 strchr(s1, m ); Locate the 1 st occurrence of m in s1. strrchr(s1, m ); Locate last occurrence of m in s1. f. strrev() It reverse all characters of a string. g. strset() It sets all characters of a string with given argument. 5. ARRAYS: Definition: An array is a collection of similar data types in which each element is located in separate memory location. Array Initialization: int a[5]=1,2,3,4,5; Five elements are stored in a a[0]=1 a[1]=2 a[0]=3 a[0]=4 a[0]=5 Characteristics of array:

19 The declaration int a [5] is nothing but creation of 5 variables of integer types in the memory. Instead of declaring 5 variables for 5 values, the programmer can define in array. All elements of an array share same name, and they are distinguished from one another with the help of an element number. The element number in an array plays major role for calling each element. An particular element of an array can be modified separately without disturbing other elements. Any element of an array a[] can be assigned/equated to another ordinary variable or an array variable of its type. Eg: b=a[2]; a [2] = a[3]; Value of a[2] is assigned to a [3]; One dimensional array: Elemnts of an integer array a[5] are stored in continuous memory locations. Integer elements requires 2 bytes. Element A[0] A[1] A[2] A[3] A[4] Address Eg: program to add even and odd numbers from 1 to 10.store them and display their results in two separate arrays. #include<stdio.h> #include<conio.h>

20 main() int sumo=0,sume=0,i=0,odd[5],even[5],a=-1,b=-1; clrscr(); for(i=1;i<=10;i++) if(i%2==0) even[++a]=i; else odd[++b]=i; printf( \n \t Even \t\t odd ); for(i=0;i<5;i++) printf( \n \t %d \t\t %d,even[i],odd[i]); sume=sume+even[i]; sumo=sumo+odd[i]; printf( \n \t ===========\n ); printf( Addition: %d %d,sume,sumo);

21 Output: Even odd =================== Addition Predefined streams: When C program is executed, a few files are automatically opened by the system for use of program. stdin,stdout,stderr are defined in standard IO files. These are pointers and defined in stdio.these are macros, stdin- identifies the standard input text. Stdout-for outputting the text.it is standard output stream. Stderr-it is an output stream in the text mode.it is a standard error stream. Two dimensional array:

22 A two dimensional array can be thought of as a rectangular display of elements with rows and columns. A two dimensional array is a collection of a number of one-dimensional arrays, which are placed one after another. Eg: int x[3] [3]; Column1 Column2 Column 3 Row1 x[0][0] x[0][1] x[0][2] Row2 x[1][0] x[1][1] x[1][2] Row 3 x[2][0] x[2][1] x[2][2] Eg: program to display the elemnts of two dimensional array #include<stdio.h> #include<conio.h> void main() int i,j; int a[3] [3]=1,2,3,4,5,6,7,8,9; clrscr(); printf( printf( Elements of an array \n\n ); for(i=0;i<3;i++) for(j=0;j<=3;j++)

23 printf( %d,a[i][j]); printf( \n ); Output: Elements of an array Three or Multidimensional arrays: C program allows array of two or multidimensions. Syntax of multidimensional array is, Array name [s1] [s2] [s3] [sn]; Where si is the size of the ith dimension Three dimensional array can be defined as follows, Int mat[3] [3] [3] = 1,2,3 4,5,6 7,8,9

24 ; 1,4,7 2,5,8 3,6,9 ; 1,4,4 2,4,7 6,6,3 ; Three dimensional arrays can be thought of as an array of arrays. Outer array contains three elements. The inner array size is two dimensional with size [3] [3]. Program: Working of three dimensional array: #include<stdio.h> #include<conio.h> main() int array_3d [3] [3] [3];

25 int a,b,c; clrscr(); for(a=0;a<3;a++) for(b=0;b<3;b++) for(c=0;c<3;c++) array_3d[a] [b] [c]=a+b+c; for( a=0;a<3;a++) printf( \n ); for(b=0;b<3;b++) for(c=0;c<3;c++) printf( %d,array_3d [a] [b] [c]); printf( \n ); Output: 0 1 2

26 sscanf(): It allows to read characters from a character array and writes them to another array. It is similar to scanf(),but instead of reading from standard input it reads data from array. sprint() It is similar to printf() except for small difference. The printf() function sends the output to the screen whereas the sprintf() function writes the values of any data type to an array of characters. Operation with arrays: Deletion Array Insertion

27 Searching Merging Sorting 6. POINTERS: Definition: A pointer is amemory variable that stores a memory address. It can have any name that is legal for another variable and it is declared in the same fashion like other variables but it is always denoted by * pointer. Features: Pointers save memory space. Execution time with the pointer is faster because data is manipulated with the address, thatis, direct access to memory location.

28 Memory is accessed efficiently with the pointers. Dynamically memory is allocated. The pointer assigns the memory space and it also releases the memory. Pointers are used with data structures. They are useful for representing two dimensional and multi-dimensional arrays. Pointer declaration: int *x; - holds the address of integer variable. floar *f; char *y; The operator * is known as indirection operator or de reference operator. The * is used for pointer declaration and dereference. When the pointer is dereferenced, the indirection operator indicates that the value stored in the pointer at that memory location is to be accessed rather than the address of a varibale. & is a address operator.it represents the address of the variable. %u is used with printf() for printing the address of a variable. Array of pointers: Program to store addresses of different elements of an array using array of pointers. #include<stdio.h> #include<conio.h> main() int *arrp[3]; int *arr1[3]=5,10,15,k; for(k=0;k<3;k++)

29 arrp[k]=arr1+k; clrscr(); printf( \n\t Address Elemt\n ); for(k=0;k<3;k++) arrp[k]=arr1+k; clrscr(): printf( \n \t Address Element\n ); for(k=0;k<3;k++) printf( \t %u,arrp[k]); printf( \t %d\n,*(arrp[k])); Output: Address element Pointers and string Program to read string from keyboard and display it using a character pointer. #include<stdio.h> #include<conio.h>

30 main() char name[15],*ch; printf( enter your name: ); gets(name); ch= name; while(*ch!= \0 ) printf( %c,*ch); ch++; output: enter your name: sakthi sakthi 7. STRUCTURE AND UNION: A structure is a collection of one or more variables of different data types grouped together under a single name. by using structures we can make a group of variables,arrays,pointers and so on. Features: To copy elements of one array to another,array of same data type elements are copied one by one. In structure, it is possible to copy the contents of all structure elements of different data types to another structures of its type using = operators. Structure elements are stored in successive memory locations. Nesting of structures is possible.(structure within structure).

31 It can handle complex data types. It is also possible to pass structure elements to a function. It is also possible to create structure pointers. Declaring Structures struct mystruct int numb; char ch; Structure has name mystruct and it contains two variables: an integer named numb and a character named ch. Declaring structure variable struct mystruct s1; Accessing Member Variables s1.numb=12; s1.ch= b ; printf( \ns1.numb=%d,s1.numb); printf( \ns1.ch=%c,s1.ch); typedef can also be used with structures. The following creates a new type sb which is of type struct chk and can be initialised as usual: typedef struct chk char name[50]; int magazinesize; float calibre; sb; ab arnies="adam",30,7; Arrays of Structure Since structures are data types that are especially useful for creating collection items, why not make a collection of them using an array? Let us now modify our above example object1.c to use an array of structures rather than individual ones. struct object char id[20]; int xpos; int ypos;

32 ; #include<stdio.h> #include<conio.h> main() struct student char name[25]; char regno[25]; int avg; char grade; stud[50],*pt; int i,no; clrscr(); printf("enter the number of the students..."); scanf("%d",&no); for(i=0;i<no;i++) printf("\n student[%d] information:\n",i+1); printf("enter the name"); scanf("%s",stud[i].name); printf("\nenter the roll no of the student"); scanf("%s",stud[i].regno); printf("\nenter the average value of the student"); scanf("%d",&stud[i].avg); pt=stud; for(pt=stud;pt<stud+no;pt++) if(pt->avg<30) pt->grade='d';

33 else if(pt->avg<50) pt->grade='c'; else if(pt->avg<70) pt->grade='b'; else pt->grade='a'; printf("\n"); printf("name REGISTER-NO AVERAGE GRADE\n"); for(pt=stud;pt<stud+no;pt++) printf("%-20s%-10s",pt->name,pt->regno); printf("%10d \t %c\n",pt->avg,pt->grade); getch(); OUTPUT Enter the number of the students 3 student[1] information: Enter the name MUNI Enter the roll no of the student 100 Enter the average value of the student 95 student[2] information: Enter the name LAK Enter the roll no of the student 200 Enter the average value of the student 55 student[3] information: Enter the name RAJA Enter the roll no of the student 300 Enter the average value of the student 25

34 NAME REGISTER-NO AVERAGE GRADE MUNI A LKA B RAJA D Unions: A union is an object that can hold any one of a set of named members. The members of the named set can be of any data type. Members are overlaid in storage. The storage allocated for a union is the storage required for the largest member of the union, plus any padding required for the union to end at a natural boundary of its strictest member. union char n; int age; float weight; people; people.n='g'; people.age=26; people.weight=64; 8. The C Preprocessor The C preprocessor modifies a source code file before handing it over to the compiler. You're most likely used to using the preprocessor to include files directly into other files, or #define constants, but the preprocessor can also be used to create "inlined" code using macros expanded at compile time and to prevent code from being compiled twice. here are essentially three uses of the preprocessor--directives, constants, and macros. Directives are commands that tell the preprocessor to skip part of a file, include another file, or define a constant or macro. Directives always begin with a sharp sign (#) and for readability should be placed flush to the left of the page. All other uses of the preprocessor involve processing #define'd constants or macros. Typically, constants and macros are written in ALL CAPS to indicate they are special. Header Files The #include directive tells the preprocessor to grab the text of a file and place it directly into the current file. Typically, such statements are placed at the top of a program--hence the name "header file" for files thus included.

35 Constants If we write #define [identifier name] [value] whenever [identifier name] shows up in the file, it will be replaced by [value]. If you are defining a constant in terms of a mathematical expression, it is wise to surround the entire value in parentheses: #define PI_PLUS_ONE ( ) By doing so, you avoid the possibility that an order of operations issue will destroy the meaning of your constant: x = PI_PLUS_ONE * 5; Without parentheses, the above would be converted to x = * 5; which would result in 1 * 5 being evaluated before the addition, not after. Oops! It is also possible to write simply #define [identifier name] which defines [identifier name] without giving it a value. This can be useful in conjunction with another set of directives that allow conditional compilation. Conditional Compilation There are a whole set of options that can be used to determine whether the preprocessor will remove lines of code before handing the file to the compiler. They include #if, #elif, #else, #ifdef, and #ifndef. An #if or #if/#elif/#else block or a #ifdef or #ifndef block must be terminated with a closing #endif. The #if directive takes a numerical argument that evaluates to true if it's nonzero. If its argument is false, then code until the closing #else, #elif, of #endif will be excluded. Commenting out Code

36 Conditional compilation is a particularly useful way to comment out a block of code that contains multi-line comments (which cannot be nested). #if 0 /* comment... */ // code /* comment */ #endif Include Guards Another common problem is that a header file is required in multiple other header files that are later included into a source code file, with the result often being that variables, structs, classes or functions appear to be defined multiple times (once for each time the header file is included). This can result in a lot of compile-time headaches. Fortunately, the preprocessor provides an easy technique for ensuring that any given file is included once and only once. By using the #ifndef directive, you can include a block of text only if a particular expression is undefined; then, within the header file, you can define the expression. This ensures that the code in the #ifndef is included only the first time the file is loaded. #ifndef _FILE_NAME_H_ #define _FILE_NAME_H_ /* code */ #endif // #ifndef _FILE_NAME_H_

37 Notice that it's not necessary to actually give a value to the expression _FILE_NAME_H_. It's sufficient to include the line "#define _FILE_NAME_H_" to make it "defined". (Note that there is an n in #ifndef--it stands for "if not defined"). A similar tactic can be used for defining specific constants, such as NULL: #ifndef NULL #define NULL (void *)0 #endif // #ifndef NULL Notice that it's useful to comment which conditional statement a particular #endif terminates. This is particularly true because preprocessor directives are rarely indented, so it can be hard to follow the flow of execution. On many compilers, the #pragma once directive can be used intead of include guards. Macros The other major use of the preprocessor is to define macros. The advantage of a macro is that it can be type-neutral (this can also be a disadvantage, of course), and it's inlined directly into the code, so there isn't any function call overhead. (Note that in C++, it's possible to get around both of these issues with templated functions and the inline keyword.) A macro definition is usually of the following form: #define MACRO_NAME(arg1, arg2,...) [code to expand to] For instance, a simple increment macro might look like this: #define INCREMENT(x) x++ They look a lot like function calls, but they're not so simple. There are actually a couple of tricky points when it comes to working with macros. First, remember that the exact text of the macro argument is "pasted in" to the macro. For instance, if you wrote something like this: #define MULT(x, y) x * y

38 and then wrote int z = MULT(3 + 2, 4 + 2); what value do you expect z to end up with? The obvious answer, 30, is wrong! That's because what happens when the macro MULT expands is that it looks like this: int z = * 4 + 2; // 2 * 4 will be evaluated first! So z would end up with the value 13! This is almost certainly not what you want to happen. The way to avoid it is to force the arguments themselves to be evaluated before the rest of the macro body. You can do this by surrounding them by parentheses in the macro definition: #define MULT(x, y) (x) * (y) // now MULT(3 + 2, 4 + 2) will expand to (3 + 2) * (4 + 2) But this isn't the only gotcha! It is also generally a good idea to surround the macro's code in parentheses if you expect it to return a value. Otherwise, you can get similar problems as when you define a constant. For instance, the following macro, which adds 5 to a given argument, has problems when embedded within a larger statement: #define ADD_FIVE(a) (a) + 5 int x = ADD_FIVE(3) * 3; // this expands to (3) + 5 * 3, so 5 * 3 is evaluated first // Now x is 18, not 24! To fix this, you generally want to surround the whole macro body with parentheses to prevent the surrounding context from affecting the macro body. #define ADD_FIVE(a) ((a) + 5) int x = ADD_FIVE(3) * 3;

39 On the other hand, if you have a multiline macro that you are using for its side effects, rather than to compute a value, you probably want to wrap it within curly braces so you don't have problems when using it following an if statement. // We use a trick involving exclusive-or to swap two variables #define SWAP(a, b) a ^= b; b ^= a; a ^= b; int x = 10; int y = 5; // works OK SWAP(x, y); // What happens now? if(x < 0) SWAP(x, y); When SWAP is expanded in the second example, only the first statement, a ^= b, is governed by the conditional; the other two statements will always execute. What we really meant was that all of the statements should be grouped together, which we can enforce using curly braces: #define SWAP(a, b) a ^= b; b ^= a; a ^= b; Now, there is still a bit more to our story! What if you write code like so: #define SWAP(a, b) a ^= b; b ^= a; a ^= b; int x = 10; int y = 5; int z = 4;

40 // What happens now? if(x < 0) else SWAP(x, y); SWAP(x, z); Then it will not compile because semicolon after the closing curly brace will break the flow between if and else. The solution? Use a do-while loop: #define SWAP(a, b) do a ^= b; b ^= a; a ^= b; while ( 0 ) int x = 10; int y = 5; int z = 4; // What happens now? if(x < 0) else SWAP(x, y); SWAP(x, z); Now the semi-colon doesn't break anything because it is part of the expression. (By the way, note that we didn't surround the arguments in parentheses because we don't expect anyone to pass an expression into swap!) Multiline macros Until now, we've seen only short, one line macros (possibly taking advantage of the semicolon to put multiple statements on one line.) It turns out that by using a the "\" to indicate a line continuation, we can write our macros across multiple lines to make them a bit more readable.

41 For instance, we could rewrite swap as #define SWAP(a, b) \ a ^= b; \ b ^= a; \ a ^= b; \ Notice that you do not need a slash at the end of the last line! The slash tells the preprocessor that the macro continues to the next line, not that the line is a continuation from a previous line. Aside from readability, writing multi-line macros may make it more obvious that you need to use curly braces to surround the body because it's more clear that multiple effects are happening at once.

Chapter 8 Character Arrays and Strings

Chapter 8 Character Arrays and Strings Chapter 8 Character Arrays and Strings INTRODUCTION A string is a sequence of characters that is treated as a single data item. String constant: String constant example. \ String constant example.\ \ includes

More information

ONE DIMENSIONAL ARRAYS

ONE DIMENSIONAL ARRAYS LECTURE 14 ONE DIMENSIONAL ARRAYS Array : An array is a fixed sized sequenced collection of related data items of same data type. In its simplest form an array can be used to represent a list of numbers

More information

CS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

More information

Computers Programming Course 11. Iulian Năstac

Computers Programming Course 11. Iulian Năstac Computers Programming Course 11 Iulian Năstac Recap from previous course Cap. Matrices (Arrays) Matrix representation is a method used by a computer language to store matrices of different dimension in

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size]; Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data

More information

Introduction to string

Introduction to string 1 Introduction to string String is a sequence of characters enclosed in double quotes. Normally, it is used for storing data like name, address, city etc. ASCII code is internally used to represent string

More information

1. Simple if statement. 2. if else statement. 3. Nested if else statement. 4. else if ladder 1. Simple if statement

1. Simple if statement. 2. if else statement. 3. Nested if else statement. 4. else if ladder 1. Simple if statement UNIT- II: Control Flow: Statements and Blocks, if, switch statements, Loops: while, do-while, for, break and continue, go to and Labels. Arrays and Strings: Introduction, One- dimensional arrays, Declaring

More information

Q 1. Attempt any TEN of the following:

Q 1. Attempt any TEN of the following: Subject Code: 17212 Model Answer Page No: 1 / 26 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The

More information

Questions Bank. 14) State any four advantages of using flow-chart

Questions Bank. 14) State any four advantages of using flow-chart Questions Bank Sub:PIC(22228) Course Code:-EJ-2I ----------------------------------------------------------------------------------------------- Chapter:-1 (Overview of C Programming)(10 Marks) 1) State

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Chapter 21: Introduction to C Programming Language

Chapter 21: Introduction to C Programming Language Ref. Page Slide 1/65 Learning Objectives In this chapter you will learn about: Features of C Various constructs and their syntax Data types and operators in C Control and Loop Structures in C Functions

More information

Computers Programming Course 10. Iulian Năstac

Computers Programming Course 10. Iulian Năstac Computers Programming Course 10 Iulian Năstac Recap from previous course 5. Values returned by a function A return statement causes execution to leave the current subroutine and resume at the point in

More information

ARRAYS(II Unit Part II)

ARRAYS(II Unit Part II) ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

/* Area and circumference of a circle */ /*celsius to fahrenheit*/

/* Area and circumference of a circle */ /*celsius to fahrenheit*/ /* Area and circumference of a circle */ #include #include #define pi 3.14 int radius; float area, circum; printf("\nenter radius of the circle : "); scanf("%d",&radius); area = pi

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

More information

Computers Programming Course 12. Iulian Năstac

Computers Programming Course 12. Iulian Năstac Computers Programming Course 12 Iulian Năstac Recap from previous course Strings in C The character string is one of the most widely used applications that involves vectors. A string in C is an array of

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1 (a) List any four relational operators.

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space

More information

EL6483: Brief Overview of C Programming Language

EL6483: Brief Overview of C Programming Language EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions

More information

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer. Functions A number of statements grouped into a single logical unit are called a function. The use of function makes programming easier since repeated statements can be grouped into functions. Splitting

More information

UNIT 3 FUNCTIONS AND ARRAYS

UNIT 3 FUNCTIONS AND ARRAYS UNIT 3 FUNCTIONS AND ARRAYS Functions Function definitions and Prototypes Calling Functions Accessing functions Passing arguments to a function - Storage Classes Scope rules Arrays Defining an array processing

More information

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful

More information

C Syntax Out: 15 September, 1995

C Syntax Out: 15 September, 1995 Burt Rosenberg Math 220/317: Programming II/Data Structures 1 C Syntax Out: 15 September, 1995 Constants. Integer such as 1, 0, 14, 0x0A. Characters such as A, B, \0. Strings such as "Hello World!\n",

More information

C Programming Multiple. Choice

C Programming Multiple. Choice C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980

More information

Write a C program using arrays and structure

Write a C program using arrays and structure 03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string

More information

8. Characters, Strings and Files

8. Characters, Strings and Files REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence

More information

Appendix G C/C++ Notes. C/C++ Coding Style Guidelines Ray Mitchell 475

Appendix G C/C++ Notes. C/C++ Coding Style Guidelines Ray Mitchell 475 C/C++ Notes C/C++ Coding Style Guidelines -0 Ray Mitchell C/C++ Notes 0 0 0 0 NOTE G. C/C++ Coding Style Guidelines. Introduction The C and C++ languages are free form, placing no significance on the column

More information

Computer Programming Unit v

Computer Programming Unit v READING AND WRITING CHARACTERS We can read and write a character on screen using printf() and scanf() function but this is not applicable in all situations. In C programming language some function are

More information

Contents. Preface. Introduction. Introduction to C Programming

Contents. Preface. Introduction. Introduction to C Programming c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical

More information

Subject: Fundamental of Computer Programming 2068

Subject: Fundamental of Computer Programming 2068 Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

More information

M1-R4: Programing and Problem Solving using C (JAN 2019)

M1-R4: Programing and Problem Solving using C (JAN 2019) M1-R4: Programing and Problem Solving using C (JAN 2019) Max Marks: 100 M1-R4-07-18 DURATION: 03 Hrs 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

Object Oriented Pragramming (22316)

Object Oriented Pragramming (22316) Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data

More information

Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore

Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore Sir Syed University of Engineering and Technology. Computer ming & Problem Solving ( CPPS ) Functions Chapter No 1 Compiled By: Sir Syed University of Engineering & Technology Computer Engineering Department

More information

UNIT I : OVERVIEW OF COMPUTERS AND C-PROGRAMMING

UNIT I : OVERVIEW OF COMPUTERS AND C-PROGRAMMING SIDDARTHA INSTITUTE OF SCIENCE AND TECHNOLOGY:: PUTTUR Siddharth Nagar, Narayanavanam Road 517583 QUESTION BANK (DESCRIPTIVE) Subject with Code : PROGRAMMING FOR PROBLEM SOLVING (18CS0501) Course & Branch

More information

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36 Department of Computer Science College of Engineering Boise State University August 25, 2017 1/36 Pointers and Arrays A pointer is a variable that stores the address of another variable. Pointers are similar

More information

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead. Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public

More information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

Unit 3 Decision making, Looping and Arrays

Unit 3 Decision making, Looping and Arrays Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

Introduction to C Language (M3-R )

Introduction to C Language (M3-R ) Introduction to C Language (M3-R4-01-18) 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in OMR answer sheet supplied with the question paper, following

More information

Government Polytechnic Muzaffarpur.

Government Polytechnic Muzaffarpur. Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: 1625408 Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking

More information

'C' Programming Language

'C' Programming Language F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax

More information

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered )   FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING ( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

More information

IV Unit Second Part STRUCTURES

IV Unit Second Part STRUCTURES STRUCTURES IV Unit Second Part Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure

More information

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++ CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

More information

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo 1. (a)what is an algorithm? Draw a flowchart to print N terms of Fibonacci

More information

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array? 1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The

More information

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Common to: CSE 2 nd sem IT 2 nd sem Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

UNIT III ARRAYS AND STRINGS

UNIT III ARRAYS AND STRINGS UNIT III ARRAYS AND STRINGS Arrays Initialization Declaration One dimensional and Two dimensional arrays. String- String operations String Arrays. Simple programs- sorting- searching matrix operations.

More information

Unit 4 Preprocessor Directives

Unit 4 Preprocessor Directives 1 What is pre-processor? The job of C preprocessor is to process the source code before it is passed to the compiler. Source Code (test.c) Pre-Processor Intermediate Code (test.i) Compiler The pre-processor

More information

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 1. Pointers As Kernighan and Ritchie state, a pointer is a variable that contains the address of a variable. They have been

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

(2½ Hours) [Total Marks: 75

(2½ Hours) [Total Marks: 75 (2½ Hours) [Total Marks: 75 N. B.: (1) All questions are compulsory. (2) Make suitable assumptions wherever necessary and state the assumptions made. (3) Answers to the same question must be written together.

More information

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR-621113 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING GE6151 COMPUTER PROGRAMMING PART A (2 MARKS QUESTION WITH ANSWERS)

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

Code No: R Set No. 1

Code No: R Set No. 1 Code No: R05010106 Set No. 1 1. (a) Draw a Flowchart for the following The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional

More information

UNIT - V STRUCTURES AND UNIONS

UNIT - V STRUCTURES AND UNIONS UNIT - V STRUCTURES AND UNIONS STRUCTURE DEFINITION A structure definition creates a format that may be used to declare structure variables. Let us use an example to illustrate the process of structure

More information

( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT V 2 MARKS

( Word to PDF Converter - Unregistered )   FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT V 2 MARKS ( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING FUNCTIONS AND POINTERS UNIT V Handling of Character Strings User-defined Functions

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

More information

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub 2Computer Science BS Degree -Imperative Programming

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

Problem Solving and 'C' Programming

Problem Solving and 'C' Programming Problem Solving and 'C' Programming Targeted at: Entry Level Trainees Session 15: Files and Preprocessor Directives/Pointers 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained

More information

UNIT-IV. Structure is a user-defined data type in C language which allows us to combine data of different types together.

UNIT-IV. Structure is a user-defined data type in C language which allows us to combine data of different types together. UNIT-IV Unit 4 Command Argument line They are parameters/arguments supplied to the program when it is invoked. They are used to control program from outside instead of hard coding those values inside the

More information

Computer Programming Unit 3

Computer Programming Unit 3 POINTERS INTRODUCTION Pointers are important in c-language. Some tasks are performed more easily with pointers such as dynamic memory allocation, cannot be performed without using pointers. So it s very

More information

Chapter 8: Character & String. In this chapter, you ll learn about;

Chapter 8: Character & String. In this chapter, you ll learn about; Chapter 8: Character & String Principles of Programming In this chapter, you ll learn about; Fundamentals of Strings and Characters The difference between an integer digit and a character digit Character

More information

UNIT-2 Introduction to C++

UNIT-2 Introduction to C++ UNIT-2 Introduction to C++ C++ CHARACTER SET Character set is asset of valid characters that a language can recognize. A character can represents any letter, digit, or any other sign. Following are some

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

Principles of C and Memory Management

Principles of C and Memory Management COMP281 Lecture 9 Principles of C and Memory Management Dr Lei Shi Last Lecture Today Pointer to Array Pointer Arithmetic Pointer with Functions struct Storage classes typedef union String struct struct

More information

Decision Making -Branching. Class Incharge: S. Sasirekha

Decision Making -Branching. Class Incharge: S. Sasirekha Decision Making -Branching Class Incharge: S. Sasirekha Branching The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the

More information

Here's how you declare a function that returns a pointer to a character:

Here's how you declare a function that returns a pointer to a character: 23 of 40 3/28/2013 10:35 PM Violets are blue Roses are red C has been around, But it is new to you! ANALYSIS: Lines 32 and 33 in main() prompt the user for the desired sort order. The value entered is

More information

Unit 7. Functions. Need of User Defined Functions

Unit 7. Functions. Need of User Defined Functions Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23. Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into

More information

COMP26120: Algorithms and Imperative Programming. Lecture 5: Program structuring, Java vs. C, and common mistakes

COMP26120: Algorithms and Imperative Programming. Lecture 5: Program structuring, Java vs. C, and common mistakes COMP26120: Algorithms and Imperative Programming Lecture 5: Program structuring, Java vs. C, and common mistakes Lecture outline Program structuring Functions (defining a functions, passing arguments and

More information

Computers Programming Course 7. Iulian Năstac

Computers Programming Course 7. Iulian Năstac Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument

More information

Tutorial No. 2 - Solution (Overview of C)

Tutorial No. 2 - Solution (Overview of C) Tutorial No. 2 - Solution (Overview of C) Computer Programming and Utilization (2110003) 1. Explain the C program development life cycle using flowchart in detail. OR Explain the process of compiling and

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

C Formatting Guidelines

C Formatting Guidelines UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO C PROGRAMMING SPRING 2012 C Formatting Guidelines Lines & Spacing 1. 100 character lines (tabs count

More information

Chapter 8 C Characters and Strings

Chapter 8 C Characters and Strings Chapter 8 C Characters and Strings Objectives of This Chapter To use the functions of the character handling library (). To use the string conversion functions of the general utilities library

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

UIC. C Programming Primer. Bharathidasan University

UIC. C Programming Primer. Bharathidasan University C Programming Primer UIC C Programming Primer Bharathidasan University Contents Getting Started 02 Basic Concepts. 02 Variables, Data types and Constants...03 Control Statements and Loops 05 Expressions

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7 Strings and Clases BIL104E: Introduction to Scientific and Engineering Computing Lecture 7 Manipulating Strings Scope and Storage Classes in C Strings Declaring a string The length of a string Copying

More information