Found 27759 Articles for Server Side Programming

Encapsulation in C++

Ankith Reddy
Updated on 24-Jun-2020 11:24:18

1K+ Views

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

Abstraction in C++

Arjun Thakur
Updated on 24-Jun-2020 11:25:15

1K+ Views

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

Classes and Objects in C++

Chandu yadav
Updated on 24-Jun-2020 11:26:13

5K+ Views

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

rand() and srand() in C

Samual Sam
Updated on 24-Jun-2020 11:26:35

12K+ Views

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

Use of fflush(stdin) in C

Samual Sam
Updated on 24-Jun-2020 11:27:30

6K+ Views

The function fflush(stdin) is used to flush the output buffer of the stream. It returns zero, if successful otherwise, returns EOF and feof error indicator is set.Here is the syntax of fflush(stdin) in C language,int fflush(FILE *stream);Here is an example of fflush(stdin) in C language,Example Live Demo#include #include int main() {    char s[20] = "Helloworld";    printf("The string : %s", s);    fflush(stdin);    return 0; }OutputThe string : Helloworld

ispunct() in C

karthikeya Boyini
Updated on 24-Jun-2020 11:28:00

80 Views

The function ispunct() is used to check that the passing character is a punctuation or not. It returns zero, if it is not a punctuation, otherwise it returns a non-zero value.Here is the syntax of ispunct() in C language, int ispunct(int character);Here is an example of ispunct() in C language, Example Live Demo#include #include int main() {    int a = '!';    int b = 'a';    if(ispunct(a))    printf("The character is a punctuation.");    else    printf("The character is not a punctuation.");    if(ispunct(b))    printf("The character is a punctuation.");    else    printf("The character is not a ... Read More

strspn() in C

Samual Sam
Updated on 24-Jun-2020 11:28:22

120 Views

The function strspn() is used to calculate the length of substring of first string which is present in second string. It returns the length of that substring.Here is the syntax of strspn() in C language,size_t strspn(const char *string1, const char *string2);Here is an example of strspn() in C language,Example Live Demo#include #include int main() {    const char s1[] = "Helloworld!";    const char s2[] = "Hello";    int length = strspn(s1, s2);    printf("The length of string : %d", length);    return 0; }OutputThe length of string : 5

strpbrk() in C

Samual Sam
Updated on 24-Jun-2020 11:16:33

918 Views

The function strpbrk() is used to find the first character of first string and matches it to any character of second string. It returns NULL, if no matches are found otherwise, it returns a pointer to the character of first string that matches to the character of second string.Here is the syntax of strpbrk() in C language, char *strpbrk(const char *string1, const char *string2)Here is an example of strpbrk() in C language, Example Live Demo#include #include int main () {    const char s1[] = "Helloworld";    const char s2[] = "Blank";    char *result;    result = strpbrk(s1, ... Read More

scanf() and fscanf() in C

karthikeya Boyini
Updated on 24-Jun-2020 11:17:07

2K+ Views

Function scanf()The function scanf() is used to read formatted input from stdin in C language. It returns the whole number of characters written in it otherwise, returns a negative value.Here is the syntax of scanf() in C language, int scanf(const char *characters_set)Here is an example of scanf() in C language, Example Live Demo#include int main () {    char s[20];    printf("Enter a string : ");    scanf("%s", s);    printf("Entered string : %s", s);    return(0); }OutputEnter a string : Peter! Entered string : Peter!Function fscanf()The function fscanf() is used to read the formatted input from the given stream ... Read More

Difference between %d and %i format specifier in C

Samual Sam
Updated on 24-Jun-2020 11:17:57

2K+ Views

Format Specifier %dThe format specifier %d takes integer value as a signed decimal integer value which means values should be decimal whether it is negative or positive.Here is an example of format specifier %d in C language, Example Live Demo#include int main() {    int v1 = 7456;    int v2 = -17346;    printf("The value in decimal form : %d", v1);    printf("The value in negative : %d", v2);    return 0; }OutputThe value in decimal form : 7456 The value in negative : -17346Format Specifier %iThe format specifier %i takes integer value as an integer value which means ... Read More

Advertisements