Difference Between Virtual and Pure Virtual Function

AmitDiwan
Updated on 24-Mar-2021 14:11:51

1K+ Views

In this post, we will understand the difference between virtual and pure virtual functions.Virtual FunctionIt has its own definition inside the class.The base class can override a virtual function.It doesn’t have a derived class.Declarationvirtual funct_name(parameter_list) {. . . . .};Pure Virtual FunctionIt doesn’t have a definition.If a class has at least one virtual function, it can be declared abstract.The derived class has to override the pure virtual function to use it.A pure virtual function is specified by placing "= 0" in its declarationDeclarationvirtual funct_name(parameter_list)=0;Following is an example −Exampleclass Box {    public:    // pure virtual function    virtual double ... Read More

Difference Between While and Do-While Loop

AmitDiwan
Updated on 24-Mar-2021 14:11:20

6K+ Views

In this post, we will understand the difference between the ‘while’ loop and the ‘do-while’ loop.while conditionThe controlling condition here appears at the beginning of the loop.The iterations do not occur if the condition at the first iteration results in False.It is also known as an entry-controlled loopThere is no condition at the end of the loop.It doesn’t need to execute at least one.Examplewhile ( condition){ statements; //body of loop }Following is the flowchart of while loop −do-while conditionThe controlling condition is present at the end of the loop.The condition is executed at least ... Read More

Difference Between For and While Loop

AmitDiwan
Updated on 24-Mar-2021 14:07:55

12K+ Views

In this post, we will understand the difference between the ‘for’ and the ‘while’ loop.For loopThe initialization, condition checking, and the iteration statements are written at the beginning of the loop.It is used only when the number of iterations is known beforehand.If the condition is not mentioned in the 'for' loop, then the loop iterates infinite number of times.The initialization is done only once, and it is never repeated.The iteration statement is written at the beginning.Hence, it executes once all statements in loop have been executed.Examplefor(initialization; condition; iteration){ //body of the 'for' loop }Following is the flowchart ... Read More

Count Frequency of Each Character in C

Bhanu Priya
Updated on 24-Mar-2021 14:06:56

883 Views

Follow the algorithm to write a C program which enables to count the frequency of each character.AlgorithmStep 1: Define MAX size. Step 2: Declare char and integer variables. Step 3: Read the string from console. Step 4: Find length of the string. Step 5: Initialize frequency of each character to 0. Step 6: Find total number of occurrences of each character. for(i=0; i='a' && string[i]='A' && string[i]

Character Operations in C Language

Bhanu Priya
Updated on 24-Mar-2021 14:05:54

659 Views

Character can be (A-Z(or) a- z), digit (0-9), a white space, or a special symbol in C programming language.DeclarationFollowing is the declaration for character operations in C programming −char a= ‘A’; using a character constant.Character input / output functionsThe character input/output functions are explained below −Example − char a;scanf("%c", &a); printf ("%c", &a); a = getchar ( ); putchar (a); a = getch ( ); putch (a);ExampleFollowing is the C program for line counting using getchar() − Live Demo#include /* count lines in input */ main(){    int count, num;    printf("enter multiple statements and Press cntrl+z:");    num = ... Read More

Pointers to Unions in C Language

Bhanu Priya
Updated on 24-Mar-2021 14:03:36

4K+ Views

A union is a memory location that is shared by several variables of different data types.SyntaxThe syntax for the pointers to unions in C programming is as follows −union uniontag{    datatype member 1;    datatype member 2;    ----    ----    datatype member n; };ExampleThe following example shows the usage of union of structure.union sample{    int a;    float b;    char c; };Declaration of union variableFollowing is the declaration for union variable. It is of three types as follows −Type 1union sample{    int a;    float b;    char c; }s;Type 2union{    int a; ... Read More

Explain Linear Data Structure: Queue in C Language

Bhanu Priya
Updated on 24-Mar-2021 13:59:45

799 Views

Data structure is collection of data organized in a structured way. It is divided into two types as explained below −Linear data structure − Data is organized in a linear fashion. For example, arrays, structures, stacks, queues, linked lists.Nonlinear data structure − Data is organized in a hierarchical way. For example, Trees, graphs, sets, tables.QueueIt is a linear data structure, where the insertion is done at rear end and the deletion is done at the front end.The order of queue is FIFO – First In First OutOperationsInsert – Inserting an element into a queue.Delete – Deleting an element from the ... Read More

Structure at Local Scope in C Language

Bhanu Priya
Updated on 24-Mar-2021 13:58:27

968 Views

Structure is a collection of different datatype variables, grouped together under a single name.General form of structure declarationThe structure declaration is as follows −struct tagname{    datatype member1;    datatype member2;    datatype member n; };Here, struct is the keyword.tagname specifies name of structure.member1, member2 specifies the data items that make up structure.ExampleThe following example shows the usage of the structure at a local scope.struct book{    int pages;    char author [30];    float price; };ExampleThe following program shows the usage the structure at a local scope. Live Demo#include struct{    char name[20];    int age;    int salary;   ... Read More

Pass Address of Structure as Argument to Function in C

Bhanu Priya
Updated on 24-Mar-2021 13:56:39

8K+ Views

There are three ways by which the values of structure can be transferred from one function to another. They are as follows −Passing individual members as arguments to function.Passing entire structure as an argument to function.Passing the address of structure as an argument to function.Now, let us understand how to pass the address of structure as an argument to function.The address of the structure is passed as an argument to the function.It is collected in a pointer to structure in function header.AdvantagesThe advantages of passing the address of structure as an argument to function are as follows −No wastage of ... Read More

C Error Handling Functions Explained

Bhanu Priya
Updated on 24-Mar-2021 13:53:46

901 Views

File is collection of records or is a place on hard disk, where data is stored permanently.Operations on filesThe operations on files in C programming language are as follows −Naming the fileOpening the fileReading from the fileWriting into the fileClosing the fileSyntaxThe syntax for opening a file is as follows −FILE *File pointer;For example, FILE * fptr;The syntax for naming a file is as follows −File pointer = fopen ("File name", "mode");For example, fptr = fopen ("sample.txt", "r"); FILE *fp; fp = fopen ("sample.txt", "w");Error Handling in FilesSome of the errors in files are as follows −Trying to read beyond ... Read More

Advertisements