Posts

Showing posts from October, 2024

Programming in C GXEST204 - KTU 2024 scheme syllabus notes pdf ------- Dr Binu V P

About me About the course- Scheme and Evaluation GXEST204 Syllabus GXEST204 Model Question Paper GXEST204 Programming in C - KTU 2024 Scheme University Question Paper GXEST204 Programming in C - KTU 2024 Scheme Introduction to C Programming Beginning with C Programming Programming in C using gcc in Linux Debugging C Program using gdb Module-1 C Fundamentals Structure of a C Program Variables and constants in C Escape Sequences Keywords and Identifiers Data Types and qualifiers   Data Type summary Primitive and Derived Data Type Preprocessor Directive Header Files in C Input-output printf() and scanf() Operators, precedence and expressions Bitwise operators in C Simple Programs to Begin with Control Statements Control statements in C if-else statement , sample programs, programs to try switch case statement, examples, programs to try looping statements, examples, programs to try. Program transfer control statements. Nesting of loops, examples, programs to try. Infinite Loops Mo...

University Question Paper GXEST204 Programming in C - KTU 2024 Scheme

 

Programming in C GXEST204 - KTU 2024 Scheme Syllabus

Image
 

About the course GXEST 204 - scheme and assesments

Image
 

Debugging C Program using gdb

Debugging  C Program using gdb Step 1. Compile the C program with debugging option -g Compile your C program with -g option. This allows the compiler to collect the debugging information. Eg:         $cc -g test.c  //test.c is the sample program to debug Step 2. Launch gdb Launch the C debugger (gdb) as shown below.     $gdb a.out Step 3. Set up a break point inside C program Syntax:     break [file_name]:line_number Eg:         break test.c:3 // this will set a break point at line number3 Places break point in the C program, where you suspect errors. While executing the program, the debugger will stop at the break point, and gives you the prompt to debug. Step 4. Execute the C program in gdb debugger You can start running the program using the run command in the gdb debugger.   Eg: run [args]  // args are optional Step 5. Printing the variable values inside gdb debugger Sy...

Programming in C using gcc in Linux

Image
If you are using Linux or UNIX, then check whether GCC is installed on your system by entering the following command from the command line − $ gcc -v If you have GNU compiler installed on your machine, then it should print a message.If GCC is not installed, then you will have to install it yourself using the detailed instructions available at https://gcc.gnu.org/install/ Install GCC The following linux command will install gcc compiler on Ubuntu 18.04 Bionic Beaver( Latest version is 20.04 Focal Fossa) .Open up terminal and enter:  $sudo apt-get install gcc Install build-essential Another way to install gcc compiler is to install it as part of build-essential package. build-essential package will also install additional libraries as well as g++ compiler. In most cases or if unsure this is exactly what you need: $sudo apt-get install build-essential Check GCC version Confirm your installation by checking for GCC version: $ gcc --version Writing first program: Following is first prog...

Beginning with C Programming

Beginning with C programming Finding a Compiler: Before we start C programming, we need to have a compiler to compile and run our programs. There are certain online compilers like  http://ideone.com/  or  https://www.onlinegdb.com/online_c_compiler that can be used to start C programming without installing a compiler. Windows: There are many compilers available freely for compilation of C programs like  Code Blocks  and  Dev-CPP. Borland C( https://developerinsider.co/download-and-install-borland-c-compiler-on-windows-10/ ), Turbo C ( https://developerinsider.co/download-turbo-c-for-windows-7-8-8-1-and-windows-10-32-64-bit-full-screen/ ) etc Linux: For Linux, gcc comes bundled with the linux, Code Blocks can also be used with Linux. This Blog has been written based on Linux and all the given examples have been compiled on the Ubuntu flavor of the Linux system.If you are using Linux or UNIX, then check whether GCC is installed on your system by entering the ...

Introduction to C programming

Image
C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was first implemented on the DEC PDP-11 computer in 1972. The main features of C language include low-level access to memory, simple set of keywords, and clean style, these features make C language suitable for system programming like operating system or compiler development.Many later languages have borrowed syntax/features directly or indirectly from C language. Like syntax of Java, PHP, JavaScript and many other languages is mainly based on C language. C++ is nearly a superset of C language having object oriented features. Ken Thompson  (left) with  Dennis Ritchie  (right, the inventor of the C programming language) In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard.When C was first written the standard was set by its authors Kernighan and Ri...

Primitive and Derived Data Type

 In the C programming language, data types are essential because they tell the compiler what kind of data a variable can hold . Choosing the correct data type improves the efficiency, clarity, and correctness of your program. Data types in C are broadly categorized into two: Primitive (Basic) Data Types Derived Data Types 🟢 1. Primitive (Basic) Data Types These are the fundamental building blocks of data in C. They are built into the language and represent the most basic kinds of data. ➤ Common Primitive Data Types: Data Type Description Example int Integer values (whole numbers) int age = 25; float Single-precision decimal values float price = 99.5; double Double-precision decimal values double pi = 3.14159; char Single characters char grade = 'A'; 📝 Note: Each type uses different memory sizes and has specific ranges . For example, int typically uses 4 bytes and ranges from -2,147,483,648 to 2,147,483,647 . 🔵 2. Derived Data Types Derived data...

Enumerated Data Type

Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.The symbolically declared members are integer constants. The keyword  enum  is used to declare an enumeration type. The general construct used to declare an enumeration type is enum tag_name {member1, member2, member3,..,member} variable1, variable2,..,variable n In this declaration, either tag_name or variable may be omitted or both may be present. But at least one of them must exist in this declaration construct. The members are integer constants. By default the first member member1 assigned value 0 member2 assigned value 1 and so on. Eg: enum week{Mon, Tue, Wed,Thu,Fri,Sat}; enum week day; // Or enum week{Mon, Tue, Wed,Thu,Fri,Sat}day; #include <stdio.h> enum day {sunday, monday, tuesday, wednesday, thursday, friday, saturday}; int main() { enum day d = thursday; printf("The day number stored in d is %d", ...

Data Types and Qualifiers in C

Image
There are four data types in C language. They are, Types Data Types   Basic data types   int, char, float, double   Enumeration data type   enum   Derived data type   pointer, array, structure, union   Void data type   void Here we will discuss only basic data types. Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. Let us briefly describe them one by one:   Following are the examples of some very common primitive data types used in C:   char:  The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers. int:  As the name suggests, an int variable is used to store an integer. float:  It is used to store decimal numbers (numbers with floating point value) with single precision. double:  It is used to store decimal numbers (numbers with floating p...

Keywords and Identifiers in C

Image
C Keywords Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier.    For example: int money;  Here, int is a keyword that indicates 'money' is a variable of type integer. As C is a case sensitive language, all keywords must be written in lowercase. Here is a list of all keywords allowed in ANSI C.There are  32 keywords . Keywords In C Along with these keywords, C supports other numerous keywords depending upon the compiler. C Identifiers Identifier refers to name given to entities such as variables, functions, structures etc. Identifier must be unique. They are created to give unique name to a entity to identify it during the execution of the program. For example:   int money; double accountBalance;  Here, money and accountBalance are identifiers.  Also remember, identifier names must be different from keywords. You cannot use 'int...

Escape Sequences

In C programming language, there are 256 numbers of characters in character set. The entire character set is divided into 2 parts i.e. the ASCII characters set and the extended ASCII characters set. But apart from that, some other characters are also there which are not the part of any characters set, known as ESCAPE characters. List of Escape Sequences \a Alarm or Beep \b Backspace \f Form Feed \n New Line \r Carriage Return \t Tab (Horizontal) \v Vertical Tab \\ Backslash \' Single Quote \" Double Quote \? Question Mark \ooo octal number \xhh hexadecimal number \0 Null

Variables and constants in C

Image
Variables In programming, a variable is a container (storage area) to hold data.To indicate the storage area, each variable should be given a unique name (identifier). Variable names are just the symbolic representation of a memory location. For example: int playerScore = 95; Here, playerScore is a variable of integer type. The variable is assigned value: 95. The value of a variable can be changed, hence the name 'variable'. In C programming, you have to declare a variable before you can use it.   Rules for naming a variable in C   A variable name can have letters (both uppercase and lowercase letters), digits and underscore only. The first letter of a variable should be either a letter or an underscore. However, it is discouraged to start variable name with an underscore. It is because variable name that starts with an underscore can conflict with system name and may cause error. There is no rule on how long a variable can be. However, only the first 31 characters of a variab...