Server Side Programming Articles - Page 1238 of 2650

What is Realloc in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:38:43

686 Views

The C library memory allocation function void *realloc(void *ptr, size_t size) attempts to resize the memory block pointed to by ptr that was previously allocated with a call to malloc or calloc.Memory allocation FunctionsMemory can be allocated in two ways as explained below −Once memory is allocated at compile time, it cannot be changed during execution. There will be a problem of either insufficiency or else wastage of memory.The solution is to create memory dynamically i.e. as per the requirement of the user during execution of program.The standard library functions which are used for dynamic memory management are as follows ... Read More

What is Calloc in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:37:07

838 Views

The C library memory allocation function void *calloc(size_t nitems, size_t size) allocates the requested memory and returns a pointer to it.The difference in malloc and calloc is that malloc does not set the memory to zero, whereas, calloc sets the allocated memory to zero.Memory allocation FunctionsMemory can be allocated in two ways as explained below −Once memory is allocated at compile time, it cannot be changed during execution. There will be a problem of either insufficiency or else wastage of memory.The solution is to create memory dynamically i.e. as per the requirement of the user during execution of program.The standard ... Read More

What is malloc in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:34:28

6K+ Views

The C library memory allocation function void *malloc(size_t size) allocates the requested memory and returns a pointer to it.Memory allocation FunctionsMemory can be allocated in two ways as explained below −Once memory is allocated at compile time, it cannot be changed during execution. There will be a problem of either insufficiency or else wastage of memory.The solution is to create memory dynamically i.e. as per the requirement of the user during execution of program.The standard library functions which are used for dynamic memory management are as follows −malloc ( )calloc ( )realloc ( )free ( )The Malloc() FunctionThis function is ... Read More

What is void pointer in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:33:07

926 Views

It is a pointer that can hold the address of any datatype variable (or) can point to any datatype variable.DeclarationThe declaration for void pointer is as follows −void *pointername;For example − void *vp;Accessing − Type cast operator is used for accessing the value of a variable through its pointer.SyntaxThe syntax for void pointer is given below −* ( (type cast) void pointer)Example 1int i=10; void *vp; vp = &i; printf ("%d", * ((int*) vp)); // int * type castExampleFollowing is the C program for void pointer − Live Demo#include main ( ){    int i =10;    float f = 5.34; ... Read More

Explain array of pointers in C programming language

Bhanu Priya
Updated on 17-Mar-2021 10:30:47

14K+ 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.Pointer declaration and initializationConsider the following statement −int qty = 179;In memory, the variable can be represented as follows −Declaring a pointerIt means ‘p’ is a pointer variable, which holds the address of another integer variable, as shown below −Int *p;Initialization of a pointerAddress operator (&) is used to initialise a pointer variable.For ... Read More

Plotting regression and residual plot in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 18:14:13

2K+ Views

To establish a simple relationship between the observations of a given joint distribution of a variable, we can create the plot for the regression model using Seaborn.To fit the dataset using the regression model, we have to first import the necessary libraries in Python.We will create plots for each regression model, (a) Linear Regression, (b) Polynomial Regression, and (c) Logistic Regression.In this example, we will use the wine quality dataset which can be accessed from here, https://archive.ics.uci.edu/ml/datasets/wine+qualityExampleimport matplotlib.pyplot as plt import seaborn as sns from scipy.stats import pearsonr sns.set(style="dark", color_codes=True) #import the dataset wine_quality = pd.read_csv('winequality-red.csv', delimiter=';') #Plotting ... Read More

How to manage image resolution of a graph in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 06:25:45

1K+ Views

An Image contains a 2-D matrix RGB data points which can be defined by the dots point per inch [ DPI ] of the image. The resolution of the image is important because a hi-resolution image will have much more clarity.We have a method ‘plt.savefig()’ in Matplotlib which determines the size of the image in terms of its pixels. Ideally it is having an ‘dpi’ parameter.Let’s see how we can manage the resolution of a graph in Matplotlib.Exampleimport matplotlib.pyplot as plt import numpy as np #Prepare the data for histogram np.random.seed(1961) nd = np.random.normal(13, 5, 1000) #Define the ... Read More

How to provide shadow effect in a Plot using path_effect attribute in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 06:25:32

1K+ Views

In order to provide path effects like shadow effect in a plot or a graph, we can use the path_effect attribute.For example, let’s see how we can use the path_effect attribute in Matplotlib add a shadow effect to a sigmoid function.import matplotlib.pyplot as plt import numpy as np from matplotlib.patheffects import PathPatchEffect, SimpleLineShadow, NormalNow let us define the size of the figure and plot the sigmoid function, plt.style.use('seaborn-deep') plt.subplots(figsize=(10, 10))Let us define the datapoints for the plot, x = np.linspace(-10, 10, 50) y = 1+ np.exp(-x))Let us define the shadow property in the plot, plt.plot(x, y, linewidth=8, color='blue', path_effects= [SimpleLineShadow(), ... Read More

How to plot with multiple color cycle using cycler property in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 06:21:53

851 Views

Matplotlib has a default color cycle for all the graphs and plots, however, in order to draw plots with multiple color cycles, we can use the cycler property of Matplotlib. It is used to plot repetitive patterns for the axis.First, we will use the Object Oriented APIs such as pyplot to plot the specific visualization.from cycler import cycler import numpy as np from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from IPython.core.display import displayIn this example, we will create two objects which will repeat the cycle after every four objects. Thus, after creating two objects, the last two ... Read More

How to plot Time Zones in a map in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 14:46:09

518 Views

Let us consider that we have some data in which we have to deal with the actual time. To plot the time-zones on the map, we can use the ‘cartopy’ or ‘metPy’ package in Python. However, we can install ‘cartopy’ package in the Anaconda environment using the commands, conda install -c conda-forge cartopyOrconda install -c conda-forge metpyNow, let’s see how to plot time zones in a map using Matplotlib.Exampleimport numpy as np import cartopy.crs as ccrs import matplotlib.animation as animation import matplotlib.pyplot as plt #Defining the plot size and axes plt.figure(figsize=(10, 9)) ax = plt.axes(projection=ccrs.PlateCarree()) #Apply the color ... Read More

Advertisements