Found 34494 Articles for Programming

Static functions in C

Samual Sam
Updated on 26-Jun-2020 08:34:44

20K+ Views

A static function in C is a function that has a scope that is limited to its object file. This means that the static function is only visible in its object file. A function can be declared as static function by placing the static keyword before the function name.An example that demonstrates this is given as follows −There are two files first_file.c and second_file.c. The contents of these files are given as follows −Contents of first_file.cstatic void staticFunc(void) {    printf("Inside the static function staticFunc() "); }Contents of second_file.cint main() {    staticFunc();    return 0; }Now, if the above ... Read More

Static Keyword in C++

Samual Sam
Updated on 30-Jul-2019 22:30:23

13K+ Views

When static keyword is used, variable or data members or functions can not be modified again. It is allocated for the lifetime of program. Static functions can be called directly by using class name. Static variables are initialized only once. Compiler persist the variable till the end of the program. Static variable can be defined inside or outside the function. They are local to the block. The default value of static variable is zero. The static variables are alive till the execution of the program. Here is the syntax of static keyword in C++ language, static datatype variable_name = ... Read More

Print 1 to 100 in C++, without loop and recursion

Samual Sam
Updated on 26-Jun-2020 08:11:52

690 Views

There are several methods to print numbers without using loops like by using recursive function, goto statement and creating a function outside main() function.Here is an example to print numbers using goto statement in C++ language,Example Live Demo#include using namespace std; int main() {    int count=1;    int x;    cout > x;    PRINT:    cout

C++ Program to Sum the digits of a given number

Samual Sam
Updated on 26-Jun-2020 08:12:52

11K+ Views

Here is an example to calculate the sum of digits in C++ language,Example Live Demo#include using namespace std; int main() {    int x, s = 0;    cout > x;    while (x != 0) {       s = s + x % 10;       x = x / 10;    }    cout

Implement your own sizeof operator using C++

karthikeya Boyini
Updated on 26-Jun-2020 08:13:26

649 Views

There is an option that we can implement our own sizeof() operator. The operator sizeof() is a unary operator and is used to calculate the size of any type of data. We can use #define directive to implement our own sizeof() operator which will work exactly same as sizeof() operator.Here is the syntax to implement own sizeof() operator, #define Any_name(object) (char *)(&object+1) - (char *)(&object)Here, Any_name − The name you want to give to your own sizeof() operator.Here is an example to implement sizeof() operator in C language, Example Live Demo#include #define to_find_size(object) (char *)(&object+1) - (char *)(&object) int main() ... Read More

What all is inherited from parent class in C++?

Samual Sam
Updated on 26-Jun-2020 08:14:35

3K+ Views

In the object-oriented programming, we can inherit the characteristics of parent class. Parent class is known as base class while child class is known as derived class. The derived class can inherit data members, member functions of base class.If the data members are public, they can be accessed by derived class, same class and outside the class. If data members are protected, they can be accessed by derived and same class only, but outside the class, they can not be accessed. If data members are private, only same class can access them.Here is an example of inheritance in C++ language, ... Read More

How will you print numbers from 1 to 100 without using loop in C?

karthikeya Boyini
Updated on 26-Jun-2020 08:15:23

3K+ Views

There are several methods to print numbers without using loops like by using recursive function, goto statement and creating a function outside main() function.Here is an example to print numbers in C language,Example Live Demo#include int number(int val) {    if(val

isgraph() C library function

karthikeya Boyini
Updated on 26-Jun-2020 08:17:52

93 Views

The function isgraph() is used to check that the passed character has a graphical representation or not. It is declared in “ctype.h” header file.Here is the syntax of isgraph() in C language, int isgraph(int char);Here is an example of isgraph() in C language, Example Live Demo#include #include int main() {    int a = '';    int b = '8';    int c = 's';    if(isgraph(a))    printf("The character has graphical representation");    else    printf("The character isn’t having graphical representation");    if(isgraph(b))    printf("The character has graphical representation");    else    printf("The character isn’t having graphical representation");    if(isgraph(c)) ... Read More

Difference between strlen() and sizeof() for string in C

karthikeya Boyini
Updated on 26-Jun-2020 08:07:54

785 Views

strlen()The function strlen() is a predefined function in C language. This is declared in “string.h” header file. It is used to get the length of array or string.Here is the syntax of strlen() in C language, size_t strlen(const char *string);Here, string − The string whose length is to be calculated.Here is an example of strlen() in C language, Example Live Demo#include #include int main () {    char s1[10] = "Hello";    int len ;    len = strlen(s1);    printf("Length of string s1 : %d", len );    return 0; }OutputLength of string s1 : 10In the above ... Read More

isupper() function in C Language

Samual Sam
Updated on 26-Jun-2020 08:10:38

2K+ Views

The function isupper() is used to check that the character is uppercase or not. It returns non-zero value if successful otherwise, return zero. It is declared in “ctype.h” header file.Here is the syntax of isupper() in C language, int isupper(int character);Here, character − The character which is to be checked.Here is an example of isupper() in C language, Example Live Demo#include #include int main() {    char val1 = 's';    char val2 = 'S';    if(isupper(val1))    printf("The character is uppercase");    else    printf("The character is not uppercase");    if(isupper(val2))    printf("The character is uppercase");    else    printf("The ... Read More

Advertisements