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

C Theory Notes

Uploaded by

Anik Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

C Theory Notes

Uploaded by

Anik Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

What is an Algorithm?

In computer programming terms, an algorithm is a set of well-defined


instructions to solve a particular problem. It takes a set of input and
produces a desired output.

Qualities of Good Algorithms


• Input and output should be defined precisely.
• Each step in the algorithm should be clear and unambiguous.
• Algorithms should be most effective among many different ways to
solve a problem.
• An algorithm shouldn't include computer code. Instead, the algorithm
should be written in such a way that it can be used in different
programming languages.

What is a Flowchart?
A flowchart is a type of diagram that represents a workflow or process. A
flowchart can also be defined as a diagrammatic representation of an
algorithm, a step-by-step approach to solving a task.
Difference between Break and Continue
reak and continue statement:
Break Statement Continue Statement

The continue statement is not


The Break statement is used to exit used to exit from the loop
from the loop constructs. constructs.

The break statement is usually


used with the switch statement, The continue statement is not
and it can also use it within the used with the switch statement,
while loop, do-while loop, or the but it can be used within the while
for-loop. loop, do-while loop, or for-loop.

When a break statement is When the continue statement is


encountered then the control is encountered then the control
exited from the loop construct automatically passed from the
immediately. beginning of the loop statement.

Difference between While and Do While Loop:

While Do While
This loop will execute the statement(s)
It checks the condition first and
at least once, then the condition is
then executes statement(s)
checked.

While loop allows initialization of Do while loop allows initialization of


counter variables before starting counter variables before and after
the body of a loop. starting the body of a loop.

It is an entry controlled loop. It is an exit controlled loop.


What is infinite loop?
An infinite loop is a looping construct that does not terminate the loop and
executes the loop forever. It is also called an indefinite loop or an endless
loop. It either produces a continuous output or no output.

example.
#include <stdio.h>
int main()
{
for(;;)
{
printf("Hello javatpoint");
}
}

What is a Null loop?


A loop which has an empty loop body is termed as a null loop.

example of a null loop: for (x=0; x<500000; x++);


Notice that in this example, a semicolon is placed directly after the closing
parenthesis of the for loop. ... Putting the semicolon directly after the for
loop (and using no braces) creates a null loop—literally, a loop that
contains no programming statements.

C String Functions

There are many important string functions defined in "string.h" library.

No. Function Description

1) strlen(string_name) returns the length of string name.

2) strcpy(destination, copies the contents of source string to


source) destination string.

3) strcat(first_string, concats or joins first string with second


second_string) string. The result of the string is stored in first
string.

4) strcmp(first_string, compares the first string with second string.


second_string) If both strings are same, it returns 0.
5) strrev(string) returns reverse string.

6) strlwr(string) returns string characters in lowercase.

7) strupr(string) returns string characters in uppercase.

What is Header file?


A header file is a file with extension .h which contains C function
declarations and macro definitions to be shared between several source
files.

What is getch() in C?
The getch() is a predefined non-standard function that is defined in conio.h
header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like
Turbo C to hold the screen until the user passes a single value to exit from
the console screen.

What is the Difference Between getch and getche?

getch vs getche
getch is a C function to read a getche is a C function to read
single character from the a single character from the
keyboard which does not display keyboard which displays
on screen and immediately immediately on screen
returned without waiting for the without waiting for the enter
enter key. key.

Input Displaying Method

getch does not display the getche displays the character


character entered by the user. entered by the user.

Syntax

getch syntax is similar to int getche syntax is similar to int


getch(void); getche(void);
Difference between Structure and Union
Struct Union

The struct keyword is used to define The union keyword is used to


a structure. define union.

Each variable member occupied a Variables members share the


unique memory space. memory space of the largest size
variable.

Changing the value of a member will Changing the value of one member
not affect other variables members. will also affect other variables
members.

Each variable member will be Only one variable member will be


assessed at a time. assessed at a time.

What is a pointer in C with example?


A pointer is a variable that stores the address of another variable. Unlike
other variables that hold values of a certain type, pointer holds the address
of a variable. For example, an integer variable holds (or you can say stores)
an integer value, however an integer pointer holds the address of a integer
variable.

You might also like