Ask a question from expert

Ask now

Programming in C and Data Structure Assignment

4 Pages1765 Words179 Views
   

Added on  2020-04-01

Programming in C and Data Structure Assignment

   Added on 2020-04-01

BookmarkShareRelated Documents
1.int – this is a primitive data type which can store a number in 32 bits, i.e. the size of this data type is 4 bytes. Therefore, the minimum value that can be stored is -231 and the maximum number that can be stored is 231 – 1.Any arithmetic calculations which are performed on the integer always gives the result in an integer.Long – this data type can store any number in 64 bits, i.e. the size is 8 bytes. And hence, the minimum number to be stored is -263 and maximum number is 263. It is used when we need a wider range of integers to be stored in memory.Short – this data type is smaller than integer as it can store up to 16bits only. The size results in 2 bytes. It is used to deal with small numbers to save memory space.Float – this data type stores single precision 32 bit IEEE 754 floating point numbers. It is used to save memory when a large number of floating point numbers are used.Double – It is double precision 64 bit IEEE 754 floating point. Its range of values is vast and therefore, is recommended not to use to store very precise values.Char – It stores a single 16 bit Unicode character. Characters in java are stored in the Unicode format ‘\u’. The minimum value that can be stored is 0 i.e. ‘\u0000’ and maximum of 65535, i.e. ‘\uffff’.Byte – Byte is the shortest data type of the data types available in java. It stores the value in 8 bits which has the minimum value as -128 and maximum as 127.The problem of this data types with arithmetic calculations are:1.The modulus operator (%) works only with integer data type and result in int. It is not suitable to work with double, float or any other data type which stores the floating points.2.The result of division operator for any 2 integers is always the integer and gives the result as the quotient of the operation. It doesn’t consider the remainder left behind.3.Char data types are only operated by addition or subtractions and result in chars. Itdoesn’t take other operators for the calculations.2.Syntax errors – These errors are those which occurs due to not following the standard syntax of the language. They can be determined when the program is compiled.Logic errors – These errors occur when the logic for a program or a part of a program is not correctly implemented. These errors are due to the lack of knowledge or the implementation. They can be determined with a step by step solution of a problem.
Programming in C and Data Structure Assignment_1
Runtime errors – these errors often occur due to typo mistake. For example to form aninfinite loop, or not to increment an iterator, divide by 0 or access an out of bound element.Semantic errors – These errors occur due to an improper and invalid use of java statements, i.e. to use the statements where it is not even valid or is necessary to use.Ex – To use a variable which is not initialized. int a;a++;//semantic error.3.Values in a primitive data type variable is stored directly in the memory. It will always have a value in it (garbage value if not initialized) but can never be null. Whereas a reference data type variable doesn’t store the value directly but is a handle to the object of the type. It is created in heap memory and can be null, if not initialized.In java, we have an upper case ‘S’ for String whereas lower case ‘s’ for short because the String is a reference data type whereas the short is primitive data type. As discussed, reference data type are the reference to the object, i.e. it is an object which is declared and hence initialized and used of a class. Here, the class name for the object of String type is String. As java uses CamelCase conventions, that’s why the we have an upper case ‘S’ for String.short is a primitive data type whose class is Short not short but we don’t use the class name to declare the variable of primitive data type as it doesn’t create a reference to the object but is directly accessed.4.Syntax error – Syntax errors in java are those errors which occurs when a standard syntax (grammar) is not followed in a sequence of characters or a set of tokens while writing a program.Ex – if a semicolon (;) is missed at the end of the statement.Incorrect: System.out.println(“Hello”)Correct: System.out.println(“Hello”);These errors are easy to handle as when the program is compiled and any syntax errors are present in the file, then the compiler shows the list of all the syntax errors that occur in the file and asks the user to correct all the errors. Even if any one error remains, then the compiler doesn’t let the programmer execute the file.Runtime error – Run time errors are those errors which are not detected at the compilation time but occurs when the program is executed. These results in abortion or the malfunctioning of the program.Ex – If a number is divided by 0.Incorrect: a = 30/0;Correct: a = 30/10;These errors are sometimes difficult to handle as they are not easily detected. If the error aborts the program, then the error is easy to find out. But if it malfunctions and
Programming in C and Data Structure Assignment_2

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Java Data Types, Expressions, Loops, and Dynamic Binding
|7
|1486
|129

2. Data Types. Student’s Name. Institutional Affiliatio
|3
|326
|23