Posts

Showing posts from September 4, 2020

What is the scope of a Variable? Explain the difference between a global and local variables with example programs.

 What is the scope of a Variable? Explain the difference between global and local variables with example programs. A scope in any programming is a region of the program where a defined variable can have its existence and beyond that variable, it cannot be accessed. There are three places where variables can be declared in C programming language − Inside a function or a block which is called  local  variables. Outside of all functions which are called  global  variables. In the definition of function parameters which are called  formal  parameters. Let us understand what are  local  and  global  variables, and  formal  parameters. Local Variables Variables that are declared inside a function or block are called local variables. They can be used only by statements that are inside that function or block of code. Local variables are not known to functions outside their own. The following example shows how local variables are u...

What is an array ? Write a C program to add two matrices of 3 x 3 using arrays.

Image
 What is an Array? Write a C program to add two matrices of 3 x 3 using arrays. Introduction to Arrays An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of the array (generally denoted by the name of the array). For simplicity, we can think of an array a fleet of stairs where on each step is placed a value (let’s say one of your friends). Here, you can identify the location of any of your friends by simply knowing the count of the step they are on. Remember: “Location of next index depends on the data type we use”. The above image can be looked at as a top-level view of a staircase where you are at the base of the staircase. Each element can be uniquely identified by their index in the array (in a similar way as you could identify your friends by...