int Return the number of characters in string s.
|
|
- Justin Short
- 6 years ago
- Views:
Transcription
1 1a.String handling functions: Function strcmp(const char *s1, const char *s2) strcpy(char *s1, const char *s2) strlen(const char *) strcat(char *s1, Data type returned int Task Compare two strings lexicographically. Return a negative value if s1<s2; 0 if s1 and s2 are identical; and a positive value if s1>s2. char* Copy string s2 to string s1. int Return the number of characters in string s. char* Concatenation s2 is appended at the end of s1. const char *s2) strlwr(char *s) char* Converts the string s to lowercase. strupr(char *s) char* Converts the string s to uppercase. strrev(char *s) char* Reverses the string s. *strncpy(char *s1, const char *s2, size_t n) strcmpi(const char *s1, const char *s2) char* int The strncpy() function is similar to strcpy(), except that not more than n bytes of s2 are copied. Thus, if there is no null byte among the first n bytes of s2, the result will not be null-terminated. Does a case insensitive comparison between two strings. //Program to demonstrate 1 st four functions char s1[20],s2[20],s3[50]; int len; printf("enter two strings\n"); scanf("%[^\n] %[^\n]",s1,s2); len=strlen(s1); printf("length of %s=%d\n",s1,len); strcpy(s3,s1); printf("s3=%s\n",s3); if(strcmp(s1,s2)==0) printf("s1 and s2 are equal\n"); else if(strcmp(s1,s2)>0) printf("s1 is greater than s2\n"); Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 1
2 else printf("s2 is greater than s1\n"); strcat(s3,s2); printf("concatenated string=%s\n",s3); 1b. char str[20]; int l,j,flag=1,i; printf("enter any string\n"); scanf("%s",str); for(l=0;str[l]!='\0';l++) ; printf("given string in reverse order\n"); for(i=l-1;i>=0;i--) putchar(str[i]); for(l=l-1,j=0;j<l;l--,j++) if(str[l]!=str[j]) flag=0; break; if(flag==1) printf("\n%s is palindrome\n",str); else printf("\n%s not palindrome\n",str); 2. Storage classes: The storage class determines the part of memory where storage allocated for a variable and how long the storage allocation continues to exist. Storage classes are of 4 types: 1. Automatic variables 2. Static variables 3. Register variables 4. External variables Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 2
3 Storage specifier auto static register extern Description Storage place: CPU Memory Initial value: garbage Scope: local Lifetime: within the function only Storage place: CPU Memory Initial value: zero Scope: local Lifetime: Retains the value of the variable between different function calls. Storage place: CPU Registers Initial value: garbage Scope: local Lifetime: within the function only Storage place: CPU Memory Initial value: zero Scope: global Lifetime: Till end of the main program. Variable definition might be anywhere in the C program. Automatic variables: int i; void autov(); for(i=1;i<=3;i++) autov(); void autov() auto int x=0; x=x+1; printf("x=%d\n",x); Output: x=1 x=1 Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 3
4 x=1 When i=1, autov() function is called for 1 st time: Because of the initial value of the automatic variables is garbage, explicitly assigning 0 to x. When x=x+1, x is incremented by 1. Then x=1 is printed. When i=2, autov() function is called for 2 nd time: Because Automatic variable s life time is local and initial value of the automatic variables is garbage, again explicitly assigning 0 to x. When x=x+1, x is incremented by 1. Then x=1 is printed. Static variables: int i; void staticv(); for(i=1;i<=3;i++) staticv(); void staticv() static int x; x=x+1; printf("x=%d\n",x); Output: x=1 x=2 x=3 When i=1, staticv() function is called for 1 st time: Because of the initial value of the static variables is zero (0), there is no need to explicit assignment of x. When x=x+1, x is incremented by 1. Then x=1 is printed. When i=2, staticv() function is called for 2 nd time: Because of static variable s life time is throughout the program, x value is retained as 1. When x=x+1, then x=1+1=2. Then x=2 is printed. Register variables: Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 4
5 register int i; void regv(); for(i=1;i<=3;i++) regv(); void regv() register int x=0; x=x+1; printf("\nx=%d",x); Output: x=1 x=1 x=1 When i=1, regv() function is called for 1 st time: Because of the initial value of the register variables is garbage, explicitly assigning 0 to x. When x=x+1, x is incremented by 1. Then x=1 is printed. When i=2, regv() function is called for 2 nd time: Because Register variable s life time is local and initial value of the automatic variables is garbage, again explicitly assigning 0 to x. When x=x+1, x is incremented by 1. Then x=1 is printed. Extern variables: extern int y; // external declaration void globe1(); void globe2(); globe1(); y=y+10; printf("in main y=%d\n",y); globe2(); void globe1() y=y+1; printf("in globe1 y=%d\n",y); int y; //definition Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 5
6 void globe2() y=y*5; printf("in globe2 y=%d\n",y); Output: In globe1 y=1 In main y=11 In globe2 y=55 Here, y is a global variable and by default initial value of global variable is zero (0). But global variable y is declared after the and globe1() functions. So, y is unavailable to those two functions even it is declared as global variable. That variable y is made available to those two functions by declaring that variable as external variable. extern int y; //external declaration (no memory is allocated to this variable). This declaration informs the compiler, that y is declared as external variable and that variable is declared as a global variable somewhere in the program. int y; //definition When this statement is encountered in the program, compiler allocates memory to that variable. 3a. Function calling mechanisms: 1. Call by value 2. Call by reference Call by value: When the function is called by value, then the actual parameters are just copied to the formal parameters. So, any operations performed on formal parameters do not reflect in the actual parameters. Here is an example to swap two numbers using call by value. In the function definition variables, the formal parameters are changed. Nut those changes are not reflected to calling function. After completion of the swap function, the actual values remain same. int a,b; Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 6
7 void swap(int,int); printf("enter a,b valuea\n"); scanf("%d%d",&a,&b); printf("before swaping a=%d\tb=%d\n",a,b); swap(a,b); printf("after swaping a=%d\tb=%d\n",a,b); void swap(int x,int y) int t=x; x=y; y=t; Output: Enter a,b values 4 5 Before swaping a=4 b=5 After swaping a=4 b=5 Call by reference: When we call the function using call by reference mechanism, the addresses of actual parameters are passed as arguments to the function call. In call by reference, the operation performed on formal parameters, affects the value of actual parameters because all the operations performed on the value stored in the address of actual parameters. Here is an example to swap two numbers using call by reference by passing addresses of variables a and b. The values of the variables have been changed after calling the swap() function because the swap happened on the addresses of the variables a and b. int a,b; void swap(int*,int*); printf("enter a,b values\n"); scanf("%d%d",&a,&b); printf("before swaping a=%d\tb=%d\n",a,b); swap(&a,&b); printf("after swaping a=%d\tb=%d\n",a,b); Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 7
8 void swap(int *x,int *y) int t=*x; *x=*y; *y=t; Output: Enter a,b values 4 5 Before swaping a=4 b=5 After swaping a=5 b=4 3b. Recursion: When the function called by itself, then that function is called recursion. Recursion function must contain termination condition. int a,b; int gcd(int,int); printf("enter 2 numbers:\n"); scanf("%d%d",&a,&b); printf("\ngreatest Common Divisor is %d\n",gcd(a,b)); int gcd(int a,int b) if(b==0) return a; else return gcd(b,a%b); 4a. Dynamic memory allocation: The process of allocating memory at run time is known as dynamic memory allocation. Dynamic memory allocation functions: 1. malloc() Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 8
9 malloc(): 2. callc() 3. realloc() 4. free() Allocates requested size of bytes and returns a pointer to the first byte of the allocated space. The malloc function reserves a block of memory of specified size and returns a pointer type of void. This means that we can assign it to any type of pointer. Initial (default) values in the allocated memory are garbage. General form: ptr=(cast type *)malloc(byte size); Example: Int *x; x=(int *)malloc(10*sizeof(int)); The function reserves a block of memory whose size (in bytes) is equivalent to 10 integer quantities. The function returns a pointer to an integer. This pointer indicates the beginning of the memory block. calloc(): Calloc allocates multiple blocks of memory each of same size and sets all bytes to zero. (Initial values in the allocated memory are zero.) - where ptr is a pointer of type cast type. - The malloc returns pointer (of cast type) to an area of memory with size byte size. General form: ptr=(cast type *)calloc(n,byte size); realloc(): Example: Int *x; x=(int *)malloc(10,sizeof(int)); Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 9
10 If the previously allocated memory is insufficient or more than required, you can change the previously allocated memory size using realloc(). General form: ptr=(cast type *)relloc(ptr, n*byte size); Here, ptr is reallocated with size of byte size (new size). free(): Already allocated memory is deallocated for further use of the memory location by another variables. General form: free(pointer); Example: free(ptr); //Example Program #include <stdio.h> #include <stdlib.h> int *ptr, i, n1, n2,*ptr1; printf("enter size of array: "); scanf("%d", &n1); ptr = (int*) calloc(n, sizeof(int)); ptr1 = (int*) malloc(n1 * sizeof(int)); printf("enter array elements\n"); for(i=0;i<n1;i++) scanf("%d",(ptr+i)); printf("array elements are\n"); for(i=0;i<n1;i++) printf("%d\t",*(ptr+i)); printf("\nenter new size of array: "); scanf("%d", &n2); ptr = (int*)realloc(ptr, n2*sizeof(int)); if(n2>n1) printf("enter %d array elements\n",n2-n1); Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 10
11 for(i=n1;i<n2;i++) scanf("%d",(ptr+i)); for(i = 0; i < n2; ++i) printf(" %d\t",*(ptr + i)); free(ptr); free(ptr1); 4b. int *a,n,i,pos=-1; void bsort(int *,int); printf("enter n value\n"); scanf("%d",&n); a=(int *)malloc(n*sizeof(int)); printf("\nenter array elements\n"); for(i=0;i<n;i++) scanf("%d",a+i); bsort(a,n); printf("array elements after sorting\n"); for(i=0;i<n;i++) printf("%d\t",*(a+i)); void bsort(int *a,int n) int i,j,t; for(i=0;i<n;i++) for(j=0;j<n-i-1;j++) if(*(a+j) > *(a+j+1)) t=*(a+j); *(a+j)=*(a+j+1); *(a+j+1)=t; Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 11
12 5a Structure Structure is a user defined data type and Heterogeneous. Structure has members with different data types. Syntax: structure <tagname> datatype1 member1; datatype2 member2;... datatypen membern; ; Structure members are accessed through structure variable and dot operator. In structure each member has separate space in memory. Take below example. struct student int rollno; char gender; float marks; s1; The total memory required to store a structure variable is equal to the sum of size of all the members. In above case 9 bytes (4+1+4) will be required to store structure variable s1. We can access any member in any sequence. s1.rollno = 20; Union Union is a user defined data type and Heterogeneous. Union has members with different data types. Syntax: union <tagname> datatype1 member1; datatype2 member2;... datatypen membern; ; Union members are accessed through Union variable and dot operator. In union, all members share the same memory space. This is the biggest difference between structure and union. union student int rollno; char gender; float marks; s1; In above example variable marks is of float type and have largest size (4 bytes). So the total memory required to store union variable s1 is 4 bytes. We can access only that variable whose value is recently stored. s1.rollno = 20; Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 12
13 4 s1.marks = 90.0; printf( %d,s1.rollno); The above code will work fine but will show erroneous output in the case of union. All the members can be initialized while declaring the variable of structure. s1.marks = 90.0; printf( %d,s1.rollno); The above code will show erroneous output. The value of rollno is lost as most recently we have stored value in marks. This is because all the members share same memory space. Only first member can be initialized while declaring the variable of union. In above example we can initialize only variable rollno at the time of declaration of variable. 5b. Pointer: A pointer is a variable that contains an address which is a location of another variable in memory. A pointer is a variable; its value is also stored in the memory in another location. Declaring and initializing pointers: datatype *ptrname; This tells the compiler 3 things about the variable ptrname. i. The asterisk (*)tells that the vaiable ptr_name is a pointer variable. ii. Ptrname needs a memory location. iii. Ptrname points to a variable of type data type. Example: int *p; declares the variable p as a pointer variable that points to an integer data type. int a,*p; p=&a; a=10; Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 13
14 6a. We assign the address of 'a' to a variable. The address of a=5000 and p=5048. Since the value of the variable p is the address of the variable a, we may access the value of 'a' by using the value of p. Therefore, the variable p points to the variable a. Program to illustrate pointer arithmetic (expressions): int x,y,*p1,*p2,s1,s2,s3; p1=&x; p2=&y; printf("enter x,y values\n"); scanf("%d%d",&x,&y); s1 = *p1 * *p2; s2 = x + *p2; s3 = *p2 / *p1-5; printf("s1=%d\ns2=%d\ns3=%d\n",s1,s2,s3); Output: Enter x,y values 4 6 s1=24 s2=10 s3=-4 I am giving only table, remaining from material. Function description Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 14
15 fopen() fclose() fgetc() fputc() fscanf() fprintf() getw() putw() fseek() ftell() rewind() create a new file or open a existing file closes a file reads a character from a file writes a character to a file reads a set of data from a file writes a set of data to a file reads a integer from a file writes a integer to a file set the position to desire point gives current position in the file set the position to the beginning of a file Prepared by Aravinda Kasukurthi, CSE, RVRJCCE 15
Unit III Functions. C functions can be classified into two categories, namely, library functions and user defined functions.
Unit III Functions Functions: Function Definition, Function prototype, types of User Defined Functions, Function calling mechanisms, Built-in string handling and character handling functions, recursion,
More informationUnit IV & V Previous Papers 1 mark Answers
1 What is pointer to structure? Pointer to structure: Unit IV & V Previous Papers 1 mark Answers The beginning address of a structure can be accessed through the use of the address (&) operator If a variable
More information// CSE/CE/IT 124 JULY 2015, 2.a. algorithm to inverse the digits of a given integer. Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0
// CSE/CE/IT 124 JULY 2015, 2a algorithm to inverse the digits of a given integer Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0 Step 4: repeat until NUMBER > 0 r=number%10; rev=rev*10+r; NUMBER=NUMBER/10;
More informationComputer 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 informationPrinciples 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 informationdynamic memory allocation
Dynamic memory allocation in C The concept of dynamic memory allocation in c language enables the C programmer to allocate memory at runtime. Dynamic memory allocation in c language is possible by 4 functions
More informationC Pointers. Abdelghani Bellaachia, CSCI 1121 Page: 1
C Pointers 1. Objective... 2 2. Introduction... 2 3. Pointer Variable Declarations and Initialization... 3 4. Reference operator (&) and Dereference operator (*) 6 5. Relation between Arrays and Pointers...
More informationMemory Allocation in C
Memory Allocation in C When a C program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment and heap segment. The text segment (also called
More informationArrays and Pointers (part 1)
Arrays and Pointers (part 1) CSE 2031 Fall 2012 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. Arrays: Example Syntax type name[size];
More informationScheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C
Sample Test Paper-I Marks : 25 Time:1 Hrs. Q1. Attempt any THREE 09 Marks a) State four relational operators with meaning. b) State the use of break statement. c) What is constant? Give any two examples.
More information2.2 Pointers. Department of CSE
2.2 Pointers 1 Department of CSE Objectives To understand the need and application of pointers To learn how to declare a pointer and how it is represented in memory To learn the relation between arrays
More informationPointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017
Pointers (part 1) EECS 2031 25 September 2017 1 What are pointers? We have seen pointers before. scanf( %f, &inches );! 2 1 Example char c; c = getchar(); printf( %c, c); char c; char *p; c = getchar();
More informationArrays and Pointers (part 1)
Arrays and Pointers (part 1) CSE 2031 Fall 2010 17 October 2010 1 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. 2 1 Arrays: Example
More informationDynamic memory allocation
Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes
More informationA. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS
Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization
More informationint marks[10]; // fixed size and fixed address No change in Memory address.
Dynamic Memory Allocation : Used When we want to allocate memory during run time. int marks[10]; // fixed size and fixed address No change in Memory address. // fixed size. ( no change in size possible
More informationPointers, Arrays, and Strings. CS449 Spring 2016
Pointers, Arrays, and Strings CS449 Spring 2016 Pointers Pointers are important. Pointers are fun! Pointers Every variable in your program has a memory location. This location can be accessed using & operator.
More informationArrays and Pointers. CSE 2031 Fall November 11, 2013
Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example
More informationQ 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'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 informationMAHARASHTRA 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 informationScheme of valuations-test 3 PART 1
Scheme of valuations-test 3 PART 1 1 a What is string? Explain with example how to pass string to a function. Ans A string constant is a one-dimensional array of characters terminated by a null ( \0 )
More informationComputer Programming: Skills & Concepts (CP) Strings
CP 14 slide 1 Tuesday 31 October 2017 Computer Programming: Skills & Concepts (CP) Strings Ajitha Rajan Tuesday 31 October 2017 Last lecture Input handling char CP 14 slide 2 Tuesday 31 October 2017 Today
More informationCSCI 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 informationUNDERSTANDING THE COMPUTER S MEMORY
POINTERS UNDERSTANDING THE COMPUTER S MEMORY Every computer has a primary memory. All our data and programs need to be placed in the primary memory for execution. The primary memory or RAM (Random Access
More informationAdvanced C Programming and Introduction to Data Structures
FYBCA Semester II (Advanced C Programming and Introduction to Data Structures) Question Bank Multiple Choice Questions Unit-1 1. Which operator is used with a pointer to access the value of the variable
More informationMODULE V: POINTERS & PREPROCESSORS
MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which
More informationLecture07: Strings, Variable Scope, Memory Model 4/8/2013
Lecture07: Strings, Variable Scope, Memory Model 4/8/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C 1 Outline Review pointers New: Strings New: Variable Scope (global vs. local variables)
More informationDynamic Memory Allocation
Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility, there are four library routines known as memory management
More informationDynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1
Dynamic Memory Dynamic Memory Allocation Strings September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Pointer arithmetic If we know the address of the first element of an array, we can compute the addresses
More informationArrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.
Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example
More informationC programming basics T3-1 -
C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of
More informationWrite 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 informationSRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY, VIRUDHUNAGAR Department of CSE & IT Internal Test I
SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY, VIRUDHUNAGAR Department of CSE & IT Internal Test I Year & Sem: I B.E (CSE) & II Date of Exam: 21/02/2015 Subject Code & Name: CS6202 & Programming & Data
More informationProgramming. Pointers, Multi-dimensional Arrays and Memory Management
Programming Pointers, Multi-dimensional Arrays and Memory Management Summary } Computer Memory } Pointers } Declaration, assignment, arithmetic and operators } Casting and printing pointers } Relationship
More informationUNIT-I Input/ Output functions and other library functions
Input and Output functions UNIT-I Input/ Output functions and other library functions All the input/output operations are carried out through function calls. There exists several functions that become
More informationBangalore South Campus
USN: 1 P E PESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities INTERNAL ASSESSMENT TEST 3 Date: 22/11/2017 Time:11:30am- 1.00 pm
More informationMemory Management. CSC215 Lecture
Memory Management CSC215 Lecture Outline Static vs Dynamic Allocation Dynamic allocation functions malloc, realloc, calloc, free Implementation Common errors Static Allocation Allocation of memory at compile-time
More informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
More informationSAE1A Programming in C. Unit : I - V
SAE1A Programming in C Unit : I - V Unit I - Overview Character set Identifier Keywords Data Types Variables Constants Operators SAE1A - Programming in C 2 Character set of C Character set is a set of
More informationCSC209H Lecture 4. Dan Zingaro. January 28, 2015
CSC209H Lecture 4 Dan Zingaro January 28, 2015 Strings (King Ch 13) String literals are enclosed in double quotes A string literal of n characters is represented as a n+1-character char array C adds a
More informationC mini reference. 5 Binary numbers 12
C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char
More informationLectures 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 informationProcedural programming with C
Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical
More informationI BCA[ ] SEMESTER I CORE: C PROGRAMMING - 106A Multiple Choice Questions.
1 of 22 8/4/2018, 4:03 PM Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008
More informationCSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings
CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Pointer Arithmetic and Element
More informationArray Initialization
Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]
More informationC Tutorial. Pointers, Dynamic Memory allocation, Valgrind, Makefile - Abhishek Yeluri and Yashwant Reddy Virupaksha
C Tutorial Pointers, Dynamic Memory allocation, Valgrind, Makefile - Abhishek Yeluri and Yashwant Reddy Virupaksha CS 370 - Operating Systems - Spring 2019 1 Outline What is a pointer? & and * operators
More informationMODULE 5: Pointers, Preprocessor Directives and Data Structures
MODULE 5: Pointers, Preprocessor Directives and Data Structures 1. What is pointer? Explain with an example program. Solution: Pointer is a variable which contains the address of another variable. Two
More informationMemory, Arrays & Pointers
1 Memory, Arrays & Pointers Memory int main() { char c; int i,j; double x; c i j x 2 Arrays Defines a block of consecutive cells int main() { int i; int a[3]; i a[0] a[1] a[2] Arrays - the [ ] operator
More informationLecture 5: Multidimensional Arrays. Wednesday, 11 February 2009
Lecture 5: Multidimensional Arrays CS209 : Algorithms and Scientific Computing Wednesday, 11 February 2009 CS209 Lecture 5: Multidimensional Arrays 1/20 In today lecture... 1 Let s recall... 2 Multidimensional
More informationPERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur
PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam-613 403 Thanjavur 01. Define program? 02. What is program development cycle? 03. What is a programming language? 04. Define algorithm? 05. What
More informationLectures 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 informationArrays, Pointers and Memory Management
Arrays, Pointers and Memory Management EECS 2031 Summer 2014 Przemyslaw Pawluk May 20, 2014 Answer to the question from last week strct->field Returns the value of field in the structure pointed to by
More informationPESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities
INTERNAL ASSESSMENT TEST-3 Date : 12-05-2016 Marks: 40 Subject & Code : Programming in C and data structures (15PCD23) Sec : F,G,H,I,J,K Name of faculty :Dr J Surya Prasad/Mr.Sreenath M V/Ms.Monika/ Time
More informationJagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming
Jagannath Institute of Management Sciences Lajpat Nagar BCA II Sem C Programming UNIT I Pointers: Introduction to Pointers, Pointer Notation,Decalaration and Initialization, Accessing variable through
More informationComputer 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 informationUnit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character
1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard
More informationPointers and File Handling
1 Pointers and File Handling From variables to their addresses Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 2 Basics of Pointers INDIAN INSTITUTE OF TECHNOLOGY
More informationIV 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 informationC: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21
Department of Computer Science College of Engineering Boise State University September 11, 2017 1/21 Pointers A pointer is a variable that stores the address of another variable. Pointers are similar to
More informationF.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 informationMODULE 1. Introduction to Data Structures
MODULE 1 Introduction to Data Structures Data Structure is a way of collecting and organizing data in such a way that we can perform operations on these data in an effective way. Data Structures is about
More information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:
More informationSri vidya college of engineering and technology UNIT II FUNCTIONS, POINTERS, STRUCTURES AND UNIONS
UNIT II FUNCTIONS, POINTERS, STRUCTURES AND UNIONS FUNCTIONS AND POINTERS Functions are created when the same process or an algorithm to be repeated several times in various places in the program. Function
More informationUnit 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 informationSubject: 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 informationExample: Structure, Union. Syntax. of Structure: struct book { char title[100]; char author[50] ]; float price; }; void main( )
Computer Programming and Utilization ( CPU) 110003 Structure, Union 1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different
More informationB.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 informationCharacter Array. C Programming. String. A sequence of characters The last character should be \0 that indicates the end of string 5 \0
Character Array C Programming Lecture 10-1:A Array &Pointer String A sequence of characters The last character should be \0 that indicates the end of string char greeting[] = "hello"; greeting 0 1 2 3
More informationCS61C Machine Structures. Lecture 5 C Structs & Memory Mangement. 1/27/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/
CS61C Machine Structures Lecture 5 C Structs & Memory Mangement 1/27/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L05 C Structs (1) C String Standard Functions
More informationAryan 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 informationCOP 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 informationDarshan Institute of Engineering & Technology for Diploma Studies Unit 5
1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different data types grouped together under a single name. Structure is
More informationPointers. Introduction
Pointers Spring Semester 2007 Programming and Data Structure 1 Introduction A pointer is a variable that represents the location (rather than the value) of a data item. They have a number of useful applications.
More informationLanguage comparison. C has pointers. Java has references. C++ has pointers and references
Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified
More informationHigh Performance Programming Programming in C part 1
High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the
More informationMemory Allocation. General Questions
General Questions 1 Memory Allocation 1. Which header file should be included to use functions like malloc() and calloc()? A. memory.h B. stdlib.h C. string.h D. dos.h 2. What function should be used to
More informationModule 6: Array in C
1 Table of Content 1. Introduction 2. Basics of array 3. Types of Array 4. Declaring Arrays 5. Initializing an array 6. Processing an array 7. Summary Learning objectives 1. To understand the concept of
More informationPDS Class Test 2. Room Sections No of students
PDS Class Test 2 Date: October 27, 2016 Time: 7pm to 8pm Marks: 20 (Weightage 50%) Room Sections No of students V1 Section 8 (All) Section 9 (AE,AG,BT,CE, CH,CS,CY,EC,EE,EX) V2 Section 9 (Rest, if not
More informationECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.
ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.
More informationE.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.
7CA00 PROBLEM SOLVING AND PROGRAMMING Academic Year : 08-09 Programme : P.G-MCA Question Bank Year / Semester : I/I Course Coordinator: A.HEMA Course Objectives. To understand the various problem solving
More informationPreprocessing directives are lines in your program that start with `#'. The `#' is followed by an identifier that is the directive name.
Unit-III Preprocessor: The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it
More informationECE551 Midterm Version 1
Name: ECE551 Midterm Version 1 NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual
More informationCS1100 Introduction to Programming
CS1100 Introduction to Programming Sorting Strings and Pointers Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Lexicographic (Dictionary) Ordering Badri
More informationC: 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 informationDarshan Institute of Engineering & Technology for Diploma Studies Unit 6
1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard
More informationDynamic Allocation in C
Dynamic Allocation in C C Pointers and Arrays 1 The previous examples involved only targets that were declared as local variables. For serious development, we must also be able to create variables dynamically,
More informationC Structures & Dynamic Memory Management
C Structures & Dynamic Memory Management Goals of this Lecture Help you learn about: Structures and unions Dynamic memory management Note: Will be covered in precepts as well We look at them in more detail
More informationArrays, Strings, and Pointers
Arrays, Strings, and Pointers Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague Lecture 04 BE5B99CPL C Programming Language Jan Faigl, 2017
More information***************OUTPUT*************************** Enter the two number The addition of two number is =100
/* 1. Program to calculate the addition of two number using function */ int n1,n2,result; printf(" Enter the two number \n"); scanf("%d%d",&n1,&n2); result=addnum(n1,n2); printf(" The addition of two number
More informationSubject: 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 informationCSI 402 Lecture 2 Working with Files (Text and Binary)
CSI 402 Lecture 2 Working with Files (Text and Binary) 1 / 30 AQuickReviewofStandardI/O Recall that #include allows use of printf and scanf functions Example: int i; scanf("%d", &i); printf("value
More informationC Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review
CS 2060 Variables Variables are statically typed. Variables must be defined before they are used. You only specify the type name when you define the variable. int a, b, c; float d, e, f; char letter; //
More informationSYSC 2006 C Winter 2012
SYSC 2006 C Winter 2012 Pointers and Arrays Copyright D. Bailey, Systems and Computer Engineering, Carleton University updated Sept. 21, 2011, Oct.18, 2011,Oct. 28, 2011, Feb. 25, 2011 Memory Organization
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationChapter 14. Dynamic Data Structures. Instructor: Öğr. Gör. Okan Vardarlı. Copyright 2004 Pearson Addison-Wesley. All rights reserved.
Chapter 14 Dynamic Data Structures Instructor: Öğr. Gör. Okan Vardarlı Copyright 2004 Pearson Addison-Wesley. All rights reserved. 12-1 Dynamic Data Structure Usually, so far, the arrays and strings we
More informationA3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE
A3-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 informationIntroduction 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 informationC Tutorial Pointers, Dynamic Memory allocation, Makefile
C Tutorial Pointers, Dynamic Memory allocation, Makefile -Abhishek Yeluri and Rejina Basnet 8/23/18 CS370 - Fall 2018 Outline What is a pointer? & and * operators Pointers with Arrays and Strings Dynamic
More information