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
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
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
Pointer is a variable that stores the address of another variable.FeaturesThe features of pointer are explained below −Pointer saves the memory space.Execution time of pointer is faster because of direct access to the 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, initialization and accessingConsider 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 mentioned in the statement below −Int *p;Initialization ... Read More
The array is a group of related items that is stored with a common name.Declaring arrayThe syntax used 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 initializationRuntime initializationAn 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 argument to function.Sending the individual elements ... Read More
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
Matplotlib can wrap text automatically, but if it's too long, the text will be displayed slightly outside of the boundaries of the axis anyways.StepsCreate a new figure, or activate an existing figure, using figure().Set the axis properties using plt.axis() method.Make a variable input_text to store the string.Add text to figure, using plt.text() method where style='oblique', ha='center', va='top', ...etc.To show the figure use plt.show() method.Exampleimport matplotlib.pyplot as plt fig = plt.figure() plt.axis([0, 10, 0, 10]) input_text = 'Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy.' plt.text(5, 5, input_text, fontsize=10, style='oblique', ha='center', va='top', ... Read More
In this program, we will detect contours in an image. Contours can be explained simply as a curve joining all the continuous points having the same color or intensity. The contours are a useful tool for shape analysis and object detection and recognition.Original ImageAlgorithmStep 1: Import OpenCV. Step 2: Import matplotlib. Step 3: Read the image. Step 4: Convert the image from bgr2rgb. Step 5: Convert the rgb image to grayscale. Step 4: Perform thresholding on the image. Step 5: Find contours on the image. Step 6: Draw contours on the image. Step 7: Display the output.Example Codeimport cv2 import ... Read More
First, we can calculate the mean and standard deviation of the input data using Pandas dataframe.Then, we could plot the data using Matplotlib.StepsCreate a list and store it in data.Using Pandas, create a data frame with data (step 1), mean, std.Plot using a dataframe.To show the figure, use plt.show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt data = [-5, 1, 8, 7, 2] df = pd.DataFrame({ 'data': data, 'mean': [2.6 for i in range(len(data))], 'std': [4.673328578 for i in range(len(data))]}) df.plot() plt.show()Output
First, we can create a scatter for different data points using the scatter method, and then, we can plot the lines using the plot method.StepsCreate a new figure, or activate an existing figure with figure size(4, 3), using figure() method.Add an axis to the current figure and make it the current axes, create x using plt.axes().Draw scatter points using scatter() method.Draw line using ax.plot() method.Set the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.To show the plot, use plt.show() method.Exampleimport random import matplotlib.pyplot as plt plt.figure(figsize=(4, 3)) ax = plt.axes() ax.scatter([random.randint(1, 1000) % 50 for i ... Read More