IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

Size: px
Start display at page:

Download "IMPORTANT QUESTIONS IN C FOR THE INTERVIEW"

Transcription

1 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. It also contains certain elements of a source code that can be separated and reused later. Header files are present in /usr/include directory. 2. What is a function? What are the steps involved in using a function? Function contains a set of instructions that perform a specific task. Types of functions: In-built functions they are pre-defined and can be called directly User-defined functions user should provide prototype, definition and has to call the function. Steps involved in using a user-defined function: Prototype of the function (subroutine/routine): It defines the type of arguments/inputs passed to the function and return type of the function. There are 4 types of prototypes. Input Return Value Example No No void display() No Yes int accept() Yes No void fact(int) Yes Yes int sum(int,int) If a function doesn t return anything, then void is used. To a function, we can pass multiple inputs but only one value (may contain multiple outputs as a single pack) can be returned. Function definition: This contains the steps involved in performing the specific task. Function calling: We can call the function wherever we require by following the function s prototype. 3. Explain the steps involved in compilation? There are 4 steps involved in compilation of C program. 1. Preprocessing: 2. Assembling 3. Compiling 4. Linking 4. What are the differences between compiler and interpreter? Compiler 1. Compiler checks for errors and converts the whole language code into machine code and then creates an output file. 2. Compiler includes resources for the output file after the conversion 3. The advantage of compiler is that the end user cannot view the code. Interpreter 1. Interpreter checks for error in language code and executes them line by line. 2. In interpreter, we require resources before the execution i.e. resources are added dynamically. 3. The disadvantage of interpreter is that the end user can view the code. Compiler 1. A Compiler is needed to translate a program written in a compiled language into machineunderstandable code before you can run the Interpreter 1. A program written in an interpreted language can be run immediately after writing the code.. But such a program always needs

2 program an interpreter to translate high-level instruction into machine- understandable instructions at runtime for execution of each statement 2. When translation is done, the binary code can be saved into an application file. 3. You can keep running the application file without the compiler unless the program is updated and you have to recompile it. 2. Binary file is not stored. 3. You cannot run the program on a machine unless the right interpreter is available. 5. Explain the memory map of C? Source Code segment: The code to be executed is stored here Global or Static memory segment: Global or static variables are stored here for which the scope is from the start to the end of the program. Global variables are accessible throughout the program. Static variables are local variables belonging to a specific function and the y last for the entire period of execution. Stack: All automatic variables are created into stack area. Default storage class of any local variable is auto. This variable may be int, char, float, array, pointer, struct, union etc. It also returns function argument as well as address. It follows LIFO data structure. For a variable, it provides logical address while compiling and converts it into physical address at the time of execution. Heap: It is used for dynamic memory allocation. Its size depends upon free space in the memory. Stack Heap Global/Static Memory Segment Source Code Segment 6. What are the types of operators present in C? What is operator priority and associativity with examples? There are 6 types of operators. Arithmetic Ex :+, -, *, /,% Logical Ex: &&, Conditional Ex:<, >, <=, >=,!= Reference Ex:., &, *, -> Bit wise Ex:&,, ~, ^, >>, <<

3 Other Ex: ( ), [ ], sizeof Priority tells which operation has to be performed first in the given expression. Associativity tells whether the operation has to be performed from left to right or right to left. a=x*y++; Here, x*y is computed first and the y is incremented by 1. a=x*(y++); Here, first y is incremented and then multiplication is computed. 7. How to execute a C program without? Method 1: _start() statement1: statement 2:.. statement n: exit(0); While compiling we have to mention, cc -nostartfiles <filename> Method 2: convergence() statement1: statement 2:.. statement n: exit(0); While compiling we have to mention, cc -nostartfiles -e convergence <filename> 8. What is an array? Explain about arrays and subscript of an array? An array is a sequential memory arrangement of hierarchical elements (elements of same data type). Advantages of an array: It handles huge data and variable representation is easy. Preparation of logic is easy as it is scalable. It provides efficiency as for any number of elements only one index is maintained. They are internally self pointers. Up to 64Kb of memory can be used based on stack. Array name with its index is called Subscript of an array. To get a value from an array we have to use the index 9. What is the difference between character array and string? Explain with an example?

4 Character array is a collection of characters without '\0' at the end and we need to specify '\0' at the end. Ex: char a[15]='c', 'O', 'N', 'V', 'E', 'R', 'G', 'E', 'N', 'C', 'E'; String is a character array with '\0' at the end. Ex: char a*15+= CONVERGENCE ; 10. What is typecasting? How many types of typecasting are present? Explain. Converting one type of datatype to another datatype is called Typecasting. There are 2 types of typecasting. Implicit typecasting: In implicit typecasting, compiler itself converts the datatype value. char a='a'; char a=120; Explicit typecasting: In explicit typecasting, user has to give instructions to the compiler to execute it. int a=10,b=20; float div; div=(float)a/b; 11. What is a Structure? What is the use of structure? Explain with an example. Structure is a user-defined datatype. it is a collection of different type of variables that are referenced by a single name. It provides a convenient means of keeping related information together. Uses of structure: We can perform deep copy. We can define values to all the members of a structure while declaring. Size of a structure variable is equal to the sum of all members/ variables of structure. struct xyz int a; char name[20]; float sal; - a1=,1, convergence, ; //defining values at the time of structure declaration struct xyz a2=a1; //deep copy 12. What is structure padding? Explain the procedure to decrease the padding with example. Allocating more bits than the original size is called Padding and a structure following such padding is called Structure padding. We can reduce the padding in structures by arranging the members of the structure in proper order. To eliminate padding in structures completely we use preprocessing statement, #pragma pack (number of bytes) where number of bytes is given in powers of 2 (0 or 1). struct xyz char name[21]; int a;

5 a; short int sal; The original size of structure variable a is 27 bytes (21+4+2=27). But, it occupies 32 bytes because of structure padding (5 bytes are padded). So, if we rearrange the members of structure in proper order, we can reduce structure padding. struct xyz char name[21]; short int sal; int a; a ; Now, we can observe that the size of structure variable is 28 bytes (4 bytes reduced). Only 1 byte is padded. To eliminate padding completely, we use #pragma pack (1) struct xyz char name[21]; int a; short int sal; a ; 13. What is unnamed structure? What is the use of unnamed structures? Explain. A structure without a name is called Unnamed structure. It is useful in restricting the structure not to create more variables other than created at the time of structure definition. 14. What is Union? Explain. Union is a logical design of a structure. It is also a user-defined datatype. In union, we can store only one data member at a time among all the members declared. Size of union is the maximum size of the variable present in the union. Unions also follow padding. While creating a variable for union datatype, we can define value only to the first member. 15. What are the differences between a structure and a union? Structure Structure is a collection of different datatypes. Size of a structure is sum of all members of structure. We can define values to all the members of a structure while declaring. In a structure, we can store all the members present in it. Union Union is a logical design of a structure. Size of union is the maximum variable size present in the union. While creating a variable for union datatype, we can define value only to the first member. In union, we can store only one data member at a time among all the members declared.

6 16. Explain about typedef with an example? Typedef is used to create an alias name to an existing datatype. a) typedef int num; num a=10; //same as int a=10; b) typedef struct emp int no; a; Here a is alias name for the structure emp. 17. Explain about enum with an example? Enumeration (Enum) is a user-defined datatype which is useful to specify a specific list of named integer constants. The value of first enumeration symbol is zero. Each symbol is given a value one greater than the symbol that precedes it. We can assign any index value while initialization. enum designation manager, assistantmanager=25,hr=10, clerk; enum designation a; a=hr; printf( Value=%d\n,a); Output: What are the differences between an array and a structure? Array It is a sequential memory arrangement of homogeneous elements We can access elements of an array using index i.e. array_name[index] arr[1] Arrays cannot perform deep copy Structure It is a sequential memory arrangement of heterogeneous elements We use member access operator (.) along with structure variable to access structure members i.e. structure_variable.structure_member a.name Structures can perform deep copy 19. What is call by value and call by address in C functions? Call by value: Calling a function by passing a value or a variable that represents a value is called as Call by value. The changes made in formal arguments do not effect the actual arguments. Call by address: Calling a function by passing an address or a variable that represents an address is called as Call by address. The changes made in formal arguments effect the actual arguments. 20. What is a variadic function? Explain with an example. A function which accepts variable number of arguments is called Variadic function. Syntax: <return_type> function_name ( argument var,... ) printf() int printf (const char *control_string,... ) 21. What is a recursive function? Explain. The function calling itself in its definition is called a Recursive function.

7 By recursive function, we can avoid loops, complexity in some logic (some implementations in Data structures). Factorial program #include<stdio.h> int fact(int); int a=5; printf( Factorial of a is : %d \n, fact(a) ); int fact(int x) if(x>1) else return (x*fact(x-1)); return 1; 22. What is a pointer? What s the use of pointers? A pointer is a variable that holds the memory address. This address is the location of another object/variable in memory. Use of pointers: Addresses are global, so we can access data from memory without following the scope. We can directly interact with memory segments of the devices by using pointers. Alias names are possible. Scalability. Dynamic memory allocation. 23. What is Dangling pointer? Explain with an example. A pointer holding address of another type is called as Dangling pointer. #include<stdio.h> int *p; p=(int *)malloc(sizeof(int)); *p=10; printf( Value in address hold by p is %d\n,*p); // 10 free(p); char *q; q=(char *)malloc(sizeof(char)); *q= A ; printf( Address hold by q is %u\n,q);

8 printf( Address hold by p is %u\n,p); // Even though it is freed, p holds the same address as q printf( Value in addr hold by q is %c\n,*q); // A printf( Value in addr hold by p is %d\n,*p); // 65 To avoid such situations, assign NULL to pointer p after freeing. free(p); P=NULL; 24. What is Static and Dynamic memory allocation of pointers? Explain with an example. Static memory allocation: Assigning the address of existing variable to a pointer is called Static memory allocation. int a=5,*p; p=&a; Dynamic memory allocation: Allocating the free memory externally using functions and assigning the address to a pointer is called Dynamic memory allocation. int *p; p=(int *) malloc(sizeof(int)); The memory is allocated in heap. We can deallocate memory using free(). 25. What is pointer arithmetic? Explain with an example. Performing arithmetic operations on pointers is called Pointer arithmetic. There are only two arithmetic operations that can be performed on pointers: addition and subtraction. Pointers will increase or decrease by the length of datatype they point to. We can add or subtract integers to and from pointers. Subtraction of two pointers of same datatype gives the number of elements between the addresses pointed by those pointers. int *p,*q,*r; int s; p=(int *)malloc(sizeof(int)); q=(int *)malloc(sizeof(int)); p+q; // invalid as we cannot add two pointers s=p-q; //result is the number of elements between addresses hold by p and q r=p+2; // result is another address NOTE: Subtraction of pointers of different datatypes is possible. But we need to use typecasting.

9 26. What are pre/post increment /decrement operators present? Explain how these work with normal variables and pointers. The increment and decrement operators are ++ and --. The operator ++ adds 1 to its operand subtracts 1. Pre increment/decrement operator: The difference between the prefix and postfix forms is when you use these operators in an expression. When an increment or decrement operator precedes its operand, the increment or decrement operation is performed before obtaining the value of the operand for use in the expression. x=10; y=++x; So, value of y=11 as x is incremented by 1 and is assigned to y. x=10; y=--x; Here, value of y=9 Post increment/decrement operator: If the operator follows its operand, the value of the operand is obtained before incrementing or decrementing it. x=10; y=x++; So, value of y=10 and x=11. x=10; y=x--; Here, value of y=10 and x=9 We can perform pre/post increment /decrement operations on pointers also. int *p; p=(int *)malloc(sizeof(int)); p++; // p=p+1 => p+1*(size of the datatype of pointer) If p holds the address 100, then p++ operation results in p holding the address 104 (100+1*4). Similarly, we can perform decrement operation on pointers. 27. What is const char * and char *const pointers? const char * char name[20]; const char *p=name; We cannot make changes in name using the pointer p. But we can change the address hold by pointer p. To make changes in the name, we should use alternate ways. We cannot change the value pointed by pointer p. But we can change the pointer p itself. Note that even char const *p is the same! char *const char name[20];

10 char *const p=name; We cannot change the address hold by pointer p. But, we can make changes in name using the pointer p. We cannot change the address hold by pointer. But we can change the value pointed by p. 28. What is the difference between pointer array and pointer to an array? Pointer array can store group of addresses ( an array of pointers). int *p[5]; Pointer to an array holds the base address of an array with a given size. int (*p)[5]; 29. What is multi pointer? Explain. C Language allows declaring a pointer as a single, double, triple etc. as per the requirements. A single pointer holds the address of a value of given datatype. int a=15,*p; p=&a; A double pointer holds the address of a single pointer. int a=25,*p, **q; p=&a; q=&p; 30. What are Qualifiers and Specifiers? Explain with an example. Specifiers: We can change the range and behaviour of a variable by adding specifiers to the datatypes. Specifiers are of 4 types. a) Signed b) Unsigned c) Short d) Long signed long int takes 4 bytes of memory. short int takes 2 bytes of memory(signed or unsigned). Qualifiers: Qualifiers specify how a variable can be accessed or modified. Qualifiers are of 3 types. a) Const b) Volatile c) Restrict const: The value of variable cannot be changed via the program. volatile: Compiler is informed that the value of variable may be changed in ways not explicitly specified by the program. restrict: Used for reference purpose (passes pointers holding some values). 31. What are command line arguments? Explain with an example. If we can pass the inputs along with program name at command prompt is called Command line arguments. touch command

11 #include<stdio.h> main (int argc, char *argv[]) if(argc==1) printf( No input is given\n ); else FILE *fp; int i; for(i=1;i<argc;i++) fp=fopen(argv*i+, a ); fclose(fp); 32. Explain malloc, calloc and realloc with example? malloc function allocates given number of bytes in heap and returns the address which is of void type. A void pointer is a pointer that may point to any kind of data. Syntax: (int *)malloc (size); calloc allocates memory from heap and it initializes all the bits in the allocated space to zero. Syntax: calloc (number of blocks, blocksize); realloc is useful to reallocate the allocated memory space. If given memory is not enough, then it will allocate the memory at another location and dump the values from old memory and deallocate the old memory Syntax: new_addr=realloc (allocated memory addr, number of bytes); 33. What are Macros and conditional macros? Explain with example. Macro is a statement which replaces the statement with definition at the time of preprocessing. We cannot use macros for datatypes. Syntax: #define macroname definition #define sqr(x) x*x; Conditional macros: Conditional macros are useful to place a code in a program based on some conditions at the time of preprocessing. Some of the conditional macros are #if, #else, #elif and #endif. #include<stdio.h> #define MAX 100 int main(void) #if MAX>99 printf( Compiled for array greater tha n 99\n ): #endif return 0; 34. What are Storage classes present in C Language? Explain with examples. Storage classes provide the scope and longevity of a variable. Automatic storage class:

12 Automatic variables are local variables in a function. These variables longevity is from starting of the function to end of it. Automatic variable can be declared by using the keyword auto. The default storage class of any variable declared in a function is auto. auto int x=100; Static storage class: Static variables are local variables in a function. The variable s longevity is from the first time it is called. Then it will allocate memory, initialize value and from the next time it will continue with its previous value till the end of the program. Static variable can be declared by using the keyword static. Static variables have auto definition with zero. banner(); -- void banner() static int x=10; Global storage class: Global variables are local variables to all functions. The variable s longevity is from the start of th program to the end of the program. If we declare anything outside the function is called a global declaration, which we can access in all the functions present after the declaration. Global variables have auto definition with zero. int x=10; void banner() void display()

13 Extern storage class: Extern is useful to provide the accessibility on a global variable to the code segment where we don t have accessibility. Extern variable can be declared by using the keyword extern. extern int x; void banner() // x can be accessed here int x=10; void display() NOTE: We cannot initialize the extern variable. extern int x=10; This is invalid. But, we can initialize an extern variable if global variable is not present. Register: Registers are small memories present on the system board whose accessibility is fast when compared to other memories. The keyword used to declare such type of variable is register. register int x=10; 35. What is Deep copy and Shallow copy? Explain with an example. Deep copy: In any expression having the assignment operator, if the entire data from right side variable is copied into left side variable, then it is called Deep copy. int a=10,b; b=a;

14 Shallow copy: In any expression having the assignment operator, if the memory address of right side variable is copied into left side variable, then it is called Shallow copy. char * a= Convergence, b; b=a; 36. What is the difference between char * and string? char * is a pointer which holds the address of memory where we store character data. char * a; String is an array with collection of characters and a NULL character at the end of the data. char a* += Convergence ;

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites: C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should

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

C Programming SYLLABUS COVERAGE SYLLABUS IN DETAILS

C Programming SYLLABUS COVERAGE SYLLABUS IN DETAILS C Programming C SYLLABUS COVERAGE Introduction to Programming Fundamentals in C Operators and Expressions Data types Input-Output Library Functions Control statements Function Storage class Pointer Pointer

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

edunepal_info

edunepal_info facebook.com/edunepal.info @ edunepal_info C interview questions (1 125) C interview questions are given with the answers in this website. We have given C interview questions faced by freshers and experienced

More information

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS Pages 792 to 800 Anna Rakitianskaia, University of Pretoria INITIALISING POINTER VARIABLES Pointer variables are declared by putting

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

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

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

MODULE 5: Pointers, Preprocessor Directives and Data Structures

MODULE 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 information

Variation of Pointers

Variation of Pointers Variation of Pointers A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before

More information

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9 Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

High Performance Computing in C and C++

High Performance Computing in C and C++ High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

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

Programming and Data Structure Solved. MCQs- Part 2

Programming and Data Structure Solved. MCQs- Part 2 Programming and Data Structure Solved MCQs- Part 2 Programming and Data Structure Solved MCQs- Part 2 Unsigned integers occupies Two bytes Four bytes One byte Eight byte A weather forecasting computation

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

Motor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks

Motor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks Goanna 3.3.2 Standards Data Sheet for MISRA C:2012 misrac2012-datasheet.pdf Motor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks The following

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

CS Programming In C

CS Programming In C CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples: 1 Programming in C Pointer Variable A variable that stores a memory address Allows C programs to simulate call-by-reference Allows a programmer to create and manipulate dynamic data structures Must be

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

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

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation

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

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE COURSE TITLE C LANGUAGE DETAILED SYLLABUS SR.NO NAME OF CHAPTERS & DETAILS HOURS ALLOTTED 1 INTRODUCTION TO C LANGUAGE About C Language Advantages of C Language Disadvantages of C Language A Sample Program

More information

High Performance Programming Programming in C part 1

High 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 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

Memory Allocation in C

Memory 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 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

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

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CprE 288 Introduction to Embedded Systems Exam 1 Review.  1 CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements

More information

M1-R4: Programing and Problem Solving using C (JULY 2018)

M1-R4: Programing and Problem Solving using C (JULY 2018) M1-R4: Programing and Problem Solving using C (JULY 2018) 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 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

MISRA-C:2012 Standards Model Summary for C / C++

MISRA-C:2012 Standards Model Summary for C / C++ Version 9.7.1 Copyright 2017 Ltd. MISRA-C:2012 s Model Summary for C / C++ The tool suite is developed and certified to BS EN ISO 9001:2000 and SGS-TÜV Saar. This information is applicable to version 9.7.1

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

Dynamic memory allocation (malloc)

Dynamic memory allocation (malloc) 1 Plan for today Quick review of previous lecture Array of pointers Command line arguments Dynamic memory allocation (malloc) Structures (Ch 6) Input and Output (Ch 7) 1 Pointers K&R Ch 5 Basics: Declaration

More information

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***

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

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below: QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the

More information

Advanced C Programming and Introduction to Data Structures

Advanced 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 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

C Structures & Dynamic Memory Management

C 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 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

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture Introduction to C, Pointers June 24, 2014 Review of Last Lecture Six Great Ideas in Computer Architecture Number Representation Bits can represent anything! n bits can represent up to 2 n things Unsigned,

More information

UNIT 3 OPERATORS. [Marks- 12]

UNIT 3 OPERATORS. [Marks- 12] 1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,

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

Unit IV & V Previous Papers 1 mark Answers

Unit 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

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

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

CS 61C: Great Ideas in Computer Architecture Introduction to C

CS 61C: Great Ideas in Computer Architecture Introduction to C CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

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

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 11: Structures and Memory (yaseminb@kth.se) Overview Overview Lecture 11: Structures and Memory Structures Continued Memory Allocation Lecture 11: Structures and Memory Structures Continued Memory

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with

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

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

Chapter 2 (Dynamic variable (i.e. pointer), Static variable) Chapter 2 (Dynamic variable (i.e. pointer), Static variable) August_04 A2. Identify and explain the error in the program below. [4] #include int *pptr; void fun1() { int num; num=25; pptr= &num;

More information

First of all, it is a variable, just like other variables you studied

First of all, it is a variable, just like other variables you studied Pointers: Basics What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the address (rather than the value)

More information

Lecture 2: C Programm

Lecture 2: C Programm 0 3 E CS 1 Lecture 2: C Programm ing C Programming Procedural thought process No built in object abstractions data separate from methods/functions Low memory overhead compared to Java No overhead of classes

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Pointers, Dynamic Data, and Reference Types

Pointers, 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 information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. 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 information

Data Types and Variables in C language

Data Types and Variables in C language Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators

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

Programming in C - Part 2

Programming in C - Part 2 Programming in C - Part 2 CPSC 457 Mohammad Reza Zakerinasab May 11, 2016 These slides are forked from slides created by Mike Clark Where to find these slides and related source code? http://goo.gl/k1qixb

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

Understanding Pointers

Understanding Pointers Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer

More information

Procedures, Parameters, Values and Variables. Steven R. Bagley

Procedures, Parameters, Values and Variables. Steven R. Bagley Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.

More information

Procedural programming with C

Procedural 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 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

So far, system calls have had easy syntax. Integer, character string, and structure arguments.

So far, system calls have had easy syntax. Integer, character string, and structure arguments. Pointers Page 1 So far, system calls have had easy syntax Wednesday, September 30, 2015 10:45 AM Integer, character string, and structure arguments. But this is not always true. Today, we begin to explore

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

Axivion Bauhaus Suite Technical Factsheet MISRA

Axivion Bauhaus Suite Technical Factsheet MISRA MISRA Contents 1. C... 2 1. Misra C 2004... 2 2. Misra C 2012 (including Amendment 1). 10 3. Misra C 2012 Directives... 18 2. C++... 19 4. Misra C++ 2008... 19 1 / 31 1. C 1. Misra C 2004 MISRA Rule Severity

More information

Pointers and File Handling

Pointers 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 information

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ... Why Pointers Pointers They provide the means by which functions can modify arguments in the calling function. They support dynamic memory allocation. They provide support for dynamic data structures, such

More information

Declaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include:

Declaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include: Declarations Based on slides from K. N. King Declaration Syntax General form of a declaration: declaration-specifiers declarators ; Declaration specifiers describe the properties of the variables or functions

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

A S H O R T I S H O V E R V I E W O F T H E A N S I C P R O G R A M M I N G L A N G U A G E

A S H O R T I S H O V E R V I E W O F T H E A N S I C P R O G R A M M I N G L A N G U A G E A S H O R T I S H O V E R V I E W O F T H E A N S I C P R O G R A M M I N G L A N G U A G E IDENTIFIERS Identifiers are names of variables, functions, defined types, structures and unions, enumeration

More information

Assist. Prof. Dr. Caner ÖZCAN

Assist. Prof. Dr. Caner ÖZCAN Assist. Prof. Dr. Caner ÖZCAN Memory Structure When a variable defined it is stored somewhere in memory. Memory can be thought as block consist of cells. When a variable defined, required number of cell

More information

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science The component base of C language Nguyễn Dũng Faculty of IT Hue College of Science Content A brief history of C Standard of C Characteristics of C The C compilation model Character set and keyword Data

More information

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem: Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd

More information

In Java we have the keyword null, which is the value of an uninitialized reference type

In Java we have the keyword null, which is the value of an uninitialized reference type + More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are

More information

Fundamental of C programming. - Ompal Singh

Fundamental of C programming. - Ompal Singh Fundamental of C programming - Ompal Singh HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE

More information

Basics of Programming

Basics of Programming Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

More information

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

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

Operators & Expressions

Operators & Expressions Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

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

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

ME964 High Performance Computing for Engineering Applications

ME964 High Performance Computing for Engineering Applications ME964 High Performance Computing for Engineering Applications Quick Overview of C Programming January 20, 2011 Dan Negrut, 2011 ME964 UW-Madison There is no reason for any individual to have a computer

More information