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

c

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

c

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

What is the difference between structure and union?

 What is Enum.
An enumeration is a data type that consists of a set of named values that represent integral
constants, known as enumeration constants.
Or
It gives opportunity to invent own data-type and define what values variable of this
datatype can take
It increases the redeability of the program.
For clearence refer Sourabh Shukla

 What is call by value and call by refrence?

Call by reference in C

 In call by reference, the address of the variable is passed into the function call as the actual
parameter.

Call by value in C

o In call by value the value of the actual variable is passed in the function call in
the call by value method.
Call by
Call by Value
Reference

In this method, it passes the


In this method, it passes the value of the
address of the variable as an
variable as an argument.
argument.

In this method, the actual


In this method, the actual value is not modified.
value is modified.

eg function of paramenter of rectangle eg swap fucntion

Constructor :-
 Constructor is a member function of a class that is executed whenever we create a new object of the
class.
 The name of the constructor is same as the name of the class
 Constructor has no return type
Specialty:-
A constructor is a special method that is used to initialize newly created object and is called implicitly,
just after the memory is allocated for the object.
It is not mandatory for the coder to write a constructor for the class
When there is no constructor defined in the class by the programmer compiler implicitly provide a
default constructor for the class.
By default constructor made by compiler if we don’t make it
Box()
{ //no code inside the body
}
Program
Public Class Box
{
Private int l,b,h;
Public Box()
{
l=10; b=8; h=4;
}
Public Box(int L, int B, int H)
{
l=L; b=B;h=H;
}
Public static void main(static [] args)
{
Box b1=new Box();
Box b2 =new Box(20,15,5);
}
#include<stdio.h>

int main()

int i = 10;

static int x = i;

if (x==i)

printf("x and i are Equal\n");

return 0;

x and i are Equal


Explanation:
As x and i are equal in value, the if condition satisfies and prints “x and i are equal”.
Note: In C this same program will produce a compile-time error as, static variables are load
time entity while auto variables are run-time entity and we can not initialize any load time
variable by the run time variable.
#include <stdio.h>

#include <string.h>

int main()

printf("GEEKS size = %ld \n\n", sizeof("GEEKS"));

printf("GEEKS length = %ld \n", strlen("GEEKS"));

return 0;

Output:
GEEKS size = 6

GEEKS length = 5
Explanation:
sizeof() function returns the size of the string including null character while strlen() function
returns length of the string excluding null character.
While loop

A While loop is the most straightforward looping structure. It is an entry-controlled loop. In a


while loop, a condition is evaluated before processing a body of the loop. If a condition is true,
then and only then the body of a loop is executed.

After the body of a loop is executed, the control again goes back to the beginning, and the
condition is checked. If it is true, the same process is executed until the condition becomes
false. Once the condition becomes false, the control goes out of the loop.

In a while loop, if the condition is not true, then the body of a loop will not be executed, not
even once.

What is a Do-While Loop?


A Do-while loop is similar to the while loop except that the condition is always executed after
the body of a loop. It is also called an exit-controlled loop.

In the do-while loop, the body of a loop is always executed at least once. After the body is
executed, then it checks the condition. If the condition is true, then it will again execute the
body of a loop. Otherwise, the control is transferred out of the loop.

 While loop checks the condition first and then executes the statement(s), whereas do
while loop will execute the statement(s) at least once, then the condition is checked.

the difference between for loop and while loop is that in for loop the number of
iterations to be done is already known and is used to obtain a certain result whereas
in while loop the command runs until a certain condition is reached and the statement
is proved to be false.

Where is C used?
C programming finds its application across industries and can be used in many ways, such as:

 In embedded systems

 For the development of system applications

 For the development of desktop applications

 For the development of a majority of Adobe applications


 For the development of browsers and the different extensions for these
browsers

 In the development of databases like MySQL

 In the development of operating systems

 To produce compilers

 In IoT-related applications

Most of the operating systems are written in the C/C++ languages. These not only include
Windows or Linux (the Linux kernel is almost entirely written in C), but also Google Chrome OS,
RIM Blackberry OS 4.

Linked List
o Linked List can be defined as collection of objects called nodes that are randomly stored
in the memory.
o A node contains two fields i.e. data stored at that particular address and the pointer which
contains the address of the next node in the memory.
o The last node of the list contains pointer to the null.

Singly Linked List


o It is most common linked list. Each node has data and pointer to the next node

Doubly linked list


o We can define the doubly linked list as a linear data structure with three
parts: the data part and the other two address part. In other words, a doubly
linked list is a list that has three parts in a single node, includes one data part, a
pointer to its previous node, and a pointer to the next node.

Circular linked list

A circular linked list is a variation of a singly linked list. The only difference between
the singly linked list and a circular linked list is that the last node does not point to
any node in a singly linked list, so its link part contains a NULL value. On the other
hand, the circular linked list is a list in which the last node connects to the first
node, so the link part of the last node holds the first node's address.

Static block is a set of instructions that is run only once when a class is loaded into
memory
Variable
* which belongs to the class and initialized only once at the start of the execution.
*Don’t need any object to call
*Initialized only once

Method
the methods in Java that can be called without creating an object of class.

Functions
A function is a group of statements that together perform a task.

Pointer
The Pointer in C, is a variable that stores address of another variable.

Typecasting

 Typecasting is also called as type conversion


 It means converting one data type into another.
 float a = 1.2;
 int b = (int)a ;

OOPs (Object-Oriented Programming System)


Object means a real-world entity such as a pen, chair, table, computer, watch, etc.

Object-Oriented Programming is a methodology or paradigm to design a program


using classes and objects. It simplifies software development and maintenance by
providing some concepts:

o Object
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation

Object
Any entity that has state and behavior is known as an object. For example, a chair, pen,
table, keyboard, bike, etc. It can be physical or logical.

An Object can be defined as an instance of a class.


Example: A dog is an object because it has states like color, name, breed, etc. as well as
behaviors like wagging the tail, barking, eating, etc.

Class
A class can be defined as a blueprint from which you can create an individual
object. Class doesn't consume any space.

Suppose we have a chocolate mould which have 2 characteristic shape and size. By
using that mould we can have an choclate which would have the same characteristics
as mould even can do different experiment in to that too like adding thea almonds and
penuts into choclate or changing the colour of choclate

 So mould is the class and it will define the attribute of the resultant chocolate
 Chocolate is the object and created based on the class chocolate mould

You might also like