Posts

Data Structure 2019 Winter Paper Solution

Image
Q1 a ) define primitive and non-primitive data types with examples. 03 Ans: primitive data types primitive-data types also called system-defined data types  are data types that already defined by the system. primitive-data types are pre-defined in programming languages for use.  Examples of these data types are int, float, and characters, In some language the bool is also an example of a primitive data type. Primitive-data types has no additional methods. non-primitive data types non-primitive data types also called user-defined data types are data types that are defined or created by the user as per the need. It can be a group of primitive-data types Primitive-data types have additional methods. Examples of these data types are array and string, structure, pointers, In language like c++ and java we have the classes as non-primitive data type or user-defined data types.   b ) Differentiate linear and non-linear data structures. 04 Ans: [su_table] Linear Data Structure Non-Linear Da...

Array And String

Array An Array is group similar data of one particular data types, the array's elements are continuous in nature when the array is declared the location of the array elements is continuous in memory. advantage of the array is we can assess the similar type of data by using only one variable and as the elements of an array are continuous in memory we can assess the element just by knowing the address of the first element we will see that in pointers. We access the elements of the array by the index in c programming the index of the array starts from 0 to N-1,  where  N is the length of the array. For example, if we want to access the first element of the array then we can use array[ 0 ],  and array[ 4 ] gives us the fifth element of the array. here the 0 and the 4 is the index for the first and the fifth element of the array. // image of arrays Declaration of array: Declaration of the array is the same as declaring a variable of any other data type, but in the case of an array we ne...

Unformatted Console I/O function

Unformatted Console i/o Function The unformatted console input and output function can deal with a single character and a string of characters. Normally we use the scanf() function for input but when we use the scanf() function we need to do one thing that is pressing the enter key to evaluate the success full input. Its weakness of scanf() Function. Now to read a single character we have a function called getch() and getche(), these functions not need to press the enter key because these functions return the character that most recently typed. The getche() function echoes the characters that you typed to the screen 'e' in getche() is referred for echos. getch() just return the characters that typed without echoing iron screen. getchar() is read a single character from the standard input stream and return the corresponding integer value ( it typically ASCII value of reading character) on success. It returns EOF (End of file) on failure. It is the same as getche() but requi...

Console I/O Functions

View this gist on GitHub Input/output The information we put into a computer is called input and the information we're given from the computer is called output. There is no keyword available in c for doing input/output or I/O, all I/o in c is done by using standard library function. there are several function library is available for performing input/output. I/O library function can be classified into two broad categories 1). Console I/O functions Function to receive input from the keyboard and write output usually on the computer screen. 2). File I/O function Function to perform I/O operations on a hard disk. Here we are going to discussing on console i/o function only. The file i/o functions would be discussed in other computer. Console I/O Functions As we discuss above function to receive input from keyboard and write output on screen. The screen and keyboard together called a console. Console I/O function can be further classified into two categories formatted and unformatted c...

Int data type

Int data type int (1 sign bit + 31 data bits) keyword in C. it is used to define any positive or negative integer. According to Min, the size of int is 4 bytes which is equal to 32 bits 1 byte = 8 bits Integer is not int integer is a very very category of numbers whereas one 'int' has limited and exact amount of memory to store what is being represented by it. An int type variable in C is able to store only numbers till 2147483647. Int is a 32-bit data type when never a number is being assigned to an int type variable it is first converted to its binary representation (that is in 0's and 1's) that it is kept in memory at a specific location. An int is actually 1 sign bit + 31 data bits, that 31 bits are available for storing the number. 1 bit is represented for maintaining the sign of the number which is either + or - sign is also represented by binary digits 0-> +, 1-> - int num= 2147483647 will be converted in binary =11111111111111111111111111111111 31 digits a...

Size of Operator in C

Size of the operator in C Size of is simply returns the amount of memory allocated to data type or variable. It is a compiler time unary operator. It can be applied to any data type like integer type, float type, pointer, and also to arrays and structure. The output depended on your machines, different machines have different output of the same data type. Example: #include<stdio.h> int main() { int a=1; double b=12.5; printf("Size of char is %lu", sizeof(char)); printf("Size of int is %lu", sizeof(int)); printf("Size of float is %lu", sizeof(float)); printf("Size of double is %lu", sizeof(double)); printf("Size of a+b is %lu", sizeof(a+b)); return 0; } Output: Size of char is 1 Size of int is 2 Size of float is 4 Size of double is 8 Size of double is 8   The size of the operator also use to find the length of the array and allocate a block of memory. Example  to finding number of element in array #include<stdio.h> int main()...

Operator in C

Operators are foundation any programming language. The functionally C programming language is incomplete without the use of the operator. Operators are symbols that help us to perform specific mathematical and logical computations on the operator. Operator Symbol Operator Name Operator Type ++, -- Unary operator unary operator +, -, *, /, % Arithmetic operator Binary operator <, <=, >, >=, ==, != Relational operator Binary operator &&, ||, ! Logical operator Binary operator &, |, <<, >>, ~, ^ Bitwise operator Binary operator =, +=, -=, *=, /=, %= Assignment operator Binary operator ? : Ternary operator Ternary operator Unary operator: operator that o...

Keyword in C

Keyword in C Keywords are specific reserved words in C. Every keyword was a specific feature associated with it. Almost all of the words which help us to use the Functionality of the C language. There are a total of 32 keywords in C. int for auto enum float while void volatile char do signed return long break unsigned sizeof double continue static struct switch register union default exten if const else volatile case short goto Most of these keyword have already known to you and we discussed in the various parts of C like Datatype, storage, classes, control statement, and functions.

Identifier

Identifier An identifier is a string of alphanumeric characters that begin with an alphabetic character or underscore character that are used to represent various programming elements such as variable, Functions, array, structure, unions and so on. An identifier is a user-defined word. Also remember identifiers must be unique. They are created to give a unique name to an entity to identify it during the execution of the program and the identifier name must be different from the keyword. Rules for naming identifiers. An identifier can have letters both uppercase and lowercase letters, digit, and underscores. The first letter of an identifier should be a letter or an underscore. You can not use the keyword as an identifier. Identifier names must be unique. Example of identifier. int sum; float average; function name void sum_of_twonumber(); void _student(); int main() { int a=99 printf("%d",a); } Above program has two identifiers. main as a function n...

enum in C

Enumeration in C Enumeration (or enum) is a user-defined data type in C. It is mainly used to assign names to integer constants, the names make a program easy to read and maintain. The keyword enum is used to declare an enumeration syntax of enum.     enum enum_name {cons1, cons2, ... }; The enum keyword is also used to define the variable of the enum type. There are two ways to define the variables of enum types as follows. Declaration: enum  week {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}; enum week day;           //initialization Now in the above declaration Monday is assigned to 0, Tuesday is assigned to 1, Wednesday to 2, and so on at the and Sunday is assigned to 6. Compiler By default assigns values starting from 0. Example  to understand the working of enum in C. #include<stdio.h> enum week {Mon, Tue, Wed, Thus, Fri, Sat, Sun}; int main() { enum week day; day=Fri; printf("%d", day); return 0; } Output: 4 In above ex...