rand() and srand() in C

Samual Sam
Updated on 24-Jun-2020 11:26:35
rand()The function rand() is used to generate the pseudo random number. It returns an integer value and its range is from 0 to rand_max i.e 32767.Here is the syntax of rand() in C language, int rand(void);Here is an example of rand() in C language, Example Live Demo#include #include int main() {    printf("%d", rand());    printf("%d", rand());    return 0; }Output1804289383 846930886srand()The function srand() is used to initialize the generated pseudo random number by rand() function. It does not return anything.Here is the syntax of srand() in C language, void srand(unsigned int number);Here is an example of srand() in C ... Read More

Classes and Objects in C++

Chandu yadav
Updated on 24-Jun-2020 11:26:13
Classes are the prime features of C++ as they support OOPS concepts and are user defined data types. Classes provide the specification for an object and contain data variables as well as functions to manipulate the data in a single package.Class DefinitionsA class definition starts with the keyword class and then the class name. After that the class body is defined. It is enclosed by curly braces. A class definition should either contain a semicolon or a list of definitions after it.An example of a class definition in C++ is as follows.class student {    int rollno;    char name[50]; ... Read More

Abstraction in C++

Arjun Thakur
Updated on 24-Jun-2020 11:25:15
Abstraction involves providing only the pertinent information to the outside world and hiding the background details. It relies on the separation of interface and implementation for programming.Classes provide abstraction in C++. They provide public methods for the outside world to manipulate data and keep the rest of the class structure to themselves. So the users can use the class as required without knowing how it has been implemented internally.A program to implement abstraction in C++ using classes is given as follows.Example Live Demo#include using namespace std; class Abstraction {    private:    int length, breadth;    public:    void setValues(int ... Read More

Encapsulation in C++

Ankith Reddy
Updated on 24-Jun-2020 11:24:18
Encapsulation brings together the data and the methods that manipulate the data into a single component and protects them from outside interference. In essence, encapsulation involves bundling the data as well as the functions that use the data. Data encapsulation in lead to the very important concept of data hiding.Encapsulation in C++ is implemented using classes that are user defined data types. These classes contain data types as well as methods that are bound together.A program that represents encapsulation in C++ using classes is given as follows.Example Live Demo#include using namespace std; class EncapsulationDemo {    private:    int length, ... Read More

Local Class in C++

George John
Updated on 24-Jun-2020 11:23:17
A class declared inside a function is known as a local class in C++ as it is local to that function.An example of a local class is given as follows.#include using namespace std; void func() {    class LocalClass {    }; } int main() {    return 0; }In the above example, func() is a function and class LocalClass is defined inside the function. So, it is known as a local class.A local class name can only be used in its function and not outside it. Also, the methods of a local class must be defined inside it only. ... Read More

swap() function in C++

Samual Sam
Updated on 24-Jun-2020 11:22:01
The swap() function is used to swap two numbers. By using this function, you do not need any third variable to swap two numbers.Here is the syntax of swap() in C++ language, void swap(int variable_name1, int variable_name2);If we assign the values to variables or pass user-defined values, it will swap the values of variables but the value of variables will remain same at the actual place.Here is an example of swap() in C++ language, Example Live Demo#include using namespace std; int main() {    int x = 35, y = 75;    printf("Value of x :%d", x);    printf("Value of ... Read More

CHAR_BIT in C++

karthikeya Boyini
Updated on 24-Jun-2020 11:21:26
The CHAR_BIT is the number of bits in char. It is declared in “limits.h” header file in C++ language. It is of 8-bits per byte.Here is an example of CHAR_BIT in C++ language,Example Live Demo#include using namespace std; int main() {    int x = 28;    int a = CHAR_BIT*sizeof(x);    stack s;    cout

new and delete operator in C++

Samual Sam
Updated on 24-Jun-2020 11:20:50
The new operatorThe new operator requests for the memory allocation in heap. If the sufficient memory is available, it initializes the memory to the pointer variable and returns its address.Here is the syntax of new operator in C++ language, pointer_variable = new datatype;Here is the syntax to initialize the memory, pointer_variable = new datatype(value);Here is the syntax to allocate a block of memory, pointer_variable = new datatype[size];Here is an example of new operator in C++ language, Example#include using namespace std; int main () {    int *ptr1 = NULL;    ptr1 = new int;    float *ptr2 = new ... Read More

Add space between pagination links with CSS

Jennifer Nicholas
Updated on 24-Jun-2020 11:20:34
You can try to run the following code to add space between pagination links with CSS:ExampleLive Demo                    .demo {             display: inline-block;          }          .demo a {             color: red;             padding: 5px 12px;             text-decoration: none;             transition: background-color 2s;             border: 1px solid orange;          }          .demo a.active {             background-color: orange;             color: white;             border-radius: 5px;          }          .demo a:hover:not(.active) {             background-color: yellow;          }          .demo a:first-child {             border-top-left-radius: 10px;             border-bottom-left-radius: 10px;          }          .demo a:last-child {             border-top-right-radius: 10px;             border-bottom-right-radius: 10px;          }                     Our Quizzes                          

Ceil and floor functions in C++

karthikeya Boyini
Updated on 24-Jun-2020 11:19:37
The ceil FunctionThe ceil function returns the smallest possible integer value which is equal to the value or greater than that. This function is declared in “cmath” header file in C++ language. It takes single value whoes ceil value is to be calculated. The datatype of variable should be double/float/long double only.Here is the syntax of ceil function in C++ language, double ceil(double x); float ceil(float x);Here is an example of ceil function in C++ language, Example Live Demo#include #include using namespace std; int main() {    float var = 1234.25;    float res;    res = ceil(var);   ... Read More
Advertisements