Found 7197 Articles for C++

Nested Classes in C++

Ankith Reddy
Updated on 19-Nov-2024 18:22:30

28K+ Views

A nested class is a class that is declared in another class. The nested class is also a member variable of the enclosing class and has the same access rights as the other members. However, the member functions of the enclosing class have no special access to the members of a nested class. Syntax Here is the basic syntax defining and using nested classes in C++. class OuterClass { // Members of the outer classpublic: // Nested class definition class InnerClass { // Members of the inner class };}; Accessing Nested Classes To access a nested class from outside ... Read More

Local Class in C++

George John
Updated on 19-Nov-2024 18:22:05

3K+ Views

A class declared inside a function is known as a local class in C++ as it is local to that function, where its scope is limited to that function. Syntax Here the syntax for a local class is given as follows. #include using namespace std; void func() {  class LocalClass {  }; } int main() {  return 0; } In the above syntax, 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 ... Read More

strdup() and strdndup() in C/C++

karthikeya Boyini
Updated on 03-Dec-2024 09:44:41

7K+ Views

strdup() The function strdup() is used to duplicate a string. It returns a pointer to a null-terminated byte string. Syntax Here is the syntax of strdup() in C language, char *strdup(const char *string); Example Here is an example of strdup() in C language. #include #include int main() {  char *str = "Helloworld";  char *result;  result = strdup(str);  printf("The string : %s", result);  return 0; } Output The string : Helloworld strndup() The function strndup works similarly to the function strndup(). This function duplicates the string at most size bytes i.e. the given size in the function. It also returns ... Read More

strcoll() in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:14:50

282 Views

The function strcoll() is used to compare two strings using locale - specific collating sequence.It returns −zero, when both strings are same, greater than zero value when first string is greater than otherless than zero value, when first string is less than other.Here is the syntax of strcoll() in C language, int strcoll(const char *first_string, const char *second_string);Here is an example of strcoll() in C language, Example Live Demo#include #include int main () {    const char s1[] = "Helloworld";    const char s2[] = "Blank";    char *result;    result = strcoll(s1, s2);    if(result > 0)   ... Read More

atol(), atoll() and atof() functions in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:18:30

756 Views

atol() FunctionThe function atol() converts string into a long integer. It returns zero, when no conversion is performed. It returns the converted long int value.Here is the syntax of atol in C++ language,long int atol(const char *string)Here is an example of atol() in C++ language,Example Live Demo#include using namespace std; int main() {    long int a;    char str[20] = "538756";    a = atol(str);    cout

Const member functions in C++

Samual Sam
Updated on 24-Jun-2020 11:19:02

19K+ Views

The const member functions are the functions which are declared as constant in the program. The object called by these functions cannot be modified. It is recommended to use const keyword so that accidental changes to object are avoided.A const member function can be called by any type of object. Non-const functions can be called by non-const objects only.Here is the syntax of const member function in C++ language, datatype function_name const();Here is an example of const member function in C++, Example Live Demo#include using namespace std; class Demo {    int val;    public:    Demo(int x = 0) { ... Read More

Ceil and floor functions in C++

karthikeya Boyini
Updated on 24-Jun-2020 11:19:37

5K+ Views

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

CHAR_BIT in C++

karthikeya Boyini
Updated on 24-Jun-2020 11:21:26

870 Views

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

swap() function in C++

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

22K+ Views

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

iswdigit() function in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:09:44

233 Views

The function iswdigit() is a built-in function in C/C++. It checks whether the wide character is a decimal digit or not. It is declared in “cwctype” header file in C++ language while “ctype.h” in C language. It takes a single character which is known as wide character.The characters from 0 to 9 are classified as decimal digits. If the wide character is not a digit, it will return zero(0). If character is digit, it will return non-zero value.Here is the syntax of iswdigit() in C++ language, int iswdigit(ch)Here is an example of iswdigit() in C++ language, Example Live Demo#include #include ... Read More

Advertisements