Skip to main content

Posts

Showing posts from July, 2019

Debug 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 Syntax: print {variable} Example:     print i Step 6. Continue, stepping over and in – gdb comm

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

KTU Mandatory C programs for Laboratory and Solutions

LIST OF LAB EXPERIMENTS 1. Familiarization of Hardware Components of a Computer 2. Familiarization of Linux environment – Programming in C with Linux 3. Familiarization of console I/O and operators in C     i) Display “Hello World”     ii) Read two numbers, add them and display their sum     iii) Read the radius of a circle, calculate its area and display it 4. Evaluate the arithmetic expression ((a -b / c * d + e) * (f +g))   and display its solution. Read the values of the variables from the user through console 5. Read 3 integer values, find the largest among them. 6. Read a Natural Number and check whether the number is prime or not 7. Read a Natural Number and check whether the number is Armstrong or not 8. Read n integers, store them in an array and find their sum and average 9. Read n integers, store them in an array and search for an element in the    array using an algorithm for Linear Search 10.Read n integers, store them in an array and sort the elements in t

Programming in C using gcc in Linux

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