| data structure in computer programming |
page#1 live Explain Data Structure in C++
programming
All questions carry equal marks.
1.Write five primary data types used in "C" Programming Language.?
ANS. Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that we use in our program. These datatypes have different storage capacities.
C language supports 2 different type of data types Primary data types These are fundamental data types in C namely integer(int), float- ing(float), character(char) and void. Derived data types Derived data types are like array, function, stucture, union and pointer. Integer type Integers are used to store whole numbers. Floating type Floating types are used to store real numbers. Character type Character types are used to store characters value. void type void type means no value. This is usually used to specify the type of functions.
2. Write all the secondary data types used in "C" Program- ming language.?
ANS.Arrays: An array in C language is a collection of similar data- type, means an array can hold value of a particular data type for which it has been declared. Arrays can be created from any of the C data-types int, float, and char. So an integer array can only hold integer values and cannot hold values other than integer. Pointers are very powerful in the C language. If you are in HPC and work in the C language, you should be well aware of pointers. Pointers form a layer of indirection. The basic concept is that a pointer provides a mech- anism for determining the address of data. Pointers can reference any data type, basic or derived. However, overusing pointers can often times cause large performance hits on the code being developed. Too many layers of indirection can cause inefficiencies. To declare a pointer, preceed a variable name with an * This will define that variable name as a pointer to a type of data. The following snippet shows how to declare different types of pointers
3. What do you understand by Primitive & Structured data types of "C".?
ANS. Structures: We used variable in our C program to store value but one variable can store only single piece information (an integer can hold only one integer value) and to store similar type of values we had to declare many variables. To overcome this problem we used array which can hold numbers of similar data type. But array too have some limitations, like in our real world application we deal with set of dissimi- lar data types and single array cannot store dissimilar data.
4. Describe three steps of user define Function briefly.?
ANS. A function is a group of statements that tog ether perform a task. Every C++ prog ram has at least one function, which is main(), and all the most trivial prog rams can define additional functions. You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but log ically the division usually is so each function performs a specific task. A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function. The C++ standard library provides numerous built-in functions that your prog ram can call. For example, function strc at() to concatenate two string s, function memc py() to copy one memory location to another location and many more functions. A function is knows as with various names like a method or a sub- routine or a procedure etc.
5. What do you mean by the term "variable" and "constant".. ?
ANS. During programming we need to store data. This data is stored in variables. Variables are locations in memory for storing data. The memory is divided into blocks. It can be viewed as pigeon-holes. You can also think of it as PO Boxes. In post offices there are different boxes and each has an address. Similarly in memory, there is a numerical address for each location of memory (block). It is difficult for us to handle these numerical addresses in our programs. So we give a name to these loca- tions. These names are variables. We call them variables because they can contain different values at different times. The constants refer to fixed values that the program may not alter dur- ing its execution. These fixed values are also called literals.