Found 26504 Articles for Server Side Programming

What is strrev() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 10:01:46

4K+ Views

An array of characters is called a string.DeclarationThe syntax for declaring an array is as follows −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.The strrev( ) FunctionThis function is used for reversing a string.The reversed string is stored in the same string.SyntaxThe syntax for strrev() function is as follows −strrev (string)ExampleThe following program shows the usage of strrev() function.#include main ( ... Read More

What is strncpy() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 09:50:54

765 Views

The C library function char *strncpy(char *dest, const char *src, size_t n) copies up to n characters from the string pointed to, by src to dest. In a case where, the length of src is less than that of n, the remainder of dest will be padded with null bytes.An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string ... Read More

Explain pointers and two-dimensional array in C language

Bhanu Priya
Updated on 17-Mar-2021 10:23:57

7K+ Views

Pointer is a variable that stores the address of another variable.FeaturesPointer saves the memory space.Execution time of pointer is faster because of direct access to memory location.With the help of pointers, the memory is accessed efficiently, i.e., memory is allocated and deallocated dynamically.Pointers are used with data structures.Pointers and two dimensional arraysMemory allocation for a two-dimensional array is as follows −int a[3] [3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};a[1] [2] = *(1234 + 1*3+2) = *(1234 + 3+2) = *(1234 + 5*4) // 4 is Scale factor = * (1234+20) = *(1254) a[1] [2] = 6ExampleFollowing ... Read More

How to send an entire array as an argument in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:00:40

300 Views

An array is a group of related items that is stored with a common name.Declaring arrayThe syntax for declaring an array is as follows −datatype array_name [size];InitializationAn array can be initialized in two ways, which are as follows −Compile time initialization.Runtime initialization.An array can also be initialized at the time of declaration as follows −int a[5] = {100, 200, 300, 400, 500};FunctionA function is a self-contained block that carries out a specific well-defined task. The two ways of passing the arrays as arguments to functions are as follows −Sending an entire array as an argument to function.Sending the individual elements ... Read More

How to find the unique rows in an R data frame?

Nizamuddin Siddiqui
Updated on 04-Mar-2021 20:44:08

1K+ Views

A unique row in an R data frame means that all the elements in that row are not repeated with the same combination in the whole data frame. In simple words, we can say that if we have a data frame called df that contains 3 columns and 5 rows then all the values in a particular row are not repeated for any other row. The search of this type of rows might be required when we have a lot of duplicate rows in our data set. To do this, we can use group_by_all function of dplyr package as shown ... Read More

How to merge two matrices by combining rows in R?

Nizamuddin Siddiqui
Updated on 04-Mar-2021 20:55:21

457 Views

By combining rows means that we want to concatenate rows of matrices but create separate columns as in the original matrices. For example, if we have two matrices say M1 and M2 as shown below −M1 1 2 3 3 2 1 M2 2 3 5 1 2 3Then merging of these two matrices by combining rows will result in −1 2 3 2 3 5 3 2 1 1 2 3Example1Live Demo> M1 M1Output      [, 1] [, 2] [1, ]  5     2 [2, ]  7     4 [3, ]  3     6 ... Read More

How to convert a binary matrix to logical matrix in R?

Nizamuddin Siddiqui
Updated on 04-Mar-2021 08:33:27

988 Views

A binary matrix contains values such as Yes or NO, 1 or 0, or any other two values that represents opposite mostly and the globally accepted logical values are FALSE and TRUE. Therefore, to convert a binary matrix to logical matrix, we can use ifelse function and convert the one category of binary variable to appropriate logical value and for the rest returns the left-out value. This is a very easy task in R, check out the below examples to understand how it can be done.Example1Live Demo> M1 M1Output[, 1] [, 2] [1, ] "No" "Yes" [2, ] "No" "No" ... Read More

How to preserve data frame structure after applying a function in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:09:17

369 Views

When we apply a function using apply family, by default the output is not in the form of a data frame. If we want to preserve the original data frame structure then we need to set the application of the apply family by setting it to the original data frame with single brackets and no arguments as shown in the below examples.Example1Consider the below data frame −Live Demo> df1 df1Output   x1 x2 1  4 2 2  6 2 3  5 2 4  2 1 5  8 4 6  7 2 7  5 3 ... Read More

How to add a new column to a data frame using mutate in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:15:15

965 Views

The mutate function of dplyr package in R can help us to add a new column to a data frame and the benefit of using mutate is that we can decide the position of the new column during the addition. For example, if we have a data frame called df that contains three columns say x, y, a then we can add a new column say z after y using mutate function. To understand how it can be done, check out the below examples.Example1Consider the below data frame −Live Demo> x1 x3 df1 df1Output   x1 x3 1  2  3 2 ... Read More

How to remove rows using character column that has elements of size less than 3 in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:20:38

547 Views

To find the number of characters in character vector elements or the elements in a character column of an R data frame, we can use nchar function. Therefore, if we want to remove rows that has elements of size less than 3 we would need to use the same function and then subset function will be used to remove the required rows as shown in the below examples.Example1Consider the below data frame −Live Demo> x1 x2 df1 df1Output    x1   x2 1  India 1 2  India 2 3  UK    1 4  UK    2 5  China 1 6 ... Read More

Advertisements