Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Header File In C Programming language

Posted by Tushar Bedekar
As We all know that in the C programming language we use to include the header files before staring the programming further. so lets view today what these header files mean to us.

As in the old programming IDE`s such as turbo c etc. we use to write as below
                          #include<stdio.h> 
#include<conio.h>        
These two are the basic header files that we usually include.There can be also different types of the header files such as<math.h>,<string.h>,<graphic.h>,<string.h>,user defined header files and many more depending on the type of the requirement in the program me written.now before moving further lets us first know what s header file.

What is Header File:-

A header file is a file with extension .h which contains C function declarations
and macro definitions and to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that come with your compiler.

You request the use of a header file in your program by including it, with the C pre-processing directive #include like you have seen inclusion of stdio.h header file, which comes along with your compiler.

Including a header file is equal to copying the content of the header file but we do not do it because it will be very much error-prone and it is not a good idea to copy the content of header file in the source files, specially if we have multiple source file comprising our program.

Include Syntax:-

Both user and system header files are included using the preprocessing directive #include. It has following two forms:
#include <file>
This form is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option while compiling your source code.
#include "file"
This form is used for header files of your own program. It searches for a file named file in the directory containing the current file. You can prepend directories to this list with the -I option while compiling your source code.

Include Operation:-

The #include directive works by directing the C preprocessor to scan the specified file as input before continuing with the rest of the current source file. The output from the preprocessor contains the output already generated, followed by the output resulting from the included file, followed by the output that comes from the text after the #include directive. For example, if you have a header file header.h as follows:
char *test (void);
and a main program called program.c that uses the header file, like this:
int x;
#include "header.h"

int main (void)
{
   puts (test ());
}
the compiler will see the same token stream as it would if program.c read
int x;
char *test (void);

int main (void)
{
   puts (test ());
}
The Next Discussion Will Be on Introduction to a various types of header files in brief. so stay connected with us.Readers One Important note for you (if any one wants to share there articles with us on any topic please click the link belowWrite for Us
Read More

The Bulid Process

Posted by Tushar Bedekar
Before Going more with this topic let us first understand what it is? Basically it is a process which takes place in order to build the .exe (executable file) from the code written in the editor or any integrated development environment.

Here this article is in the reference to the "C and C++ programming language".

C Source Code:-

The code that you have written in the editor is referred to as a source code.In "C Programming" language this source code is stored with an .c extension and in that if the C++ programming language it is being stored with the .cpp extension.

This source code includes many user

  • User defined functions   
  • Many library functions 
  • Macros Definition
  •  And native codes
for more info please refer Source Code Vs Object Code



Pre-compilation:-

Now this is the  first step in build process.During this step the C source code is get expanded on the basis of pre processor directives included in the sources code. These pre processor directives may include 
  • #include
  • #define
  • #ifdef and #pragma etc. 
During this pre compilation process the source code that is being stored in the .c format is get converted into the .I extension which is referred as the expanded source code.for example the stored in the form of tushar.c format is get converted into the form of tushar.I format. that means we can say the during the pre compilation only the extension or the format of the code changes in the first step if the build process.

Compilation:-

The remaining content will be updated within 10 hrs. so stay connected

Read More

Can we write any thing inside the main function in c?

Posted by Tushar Bedekar
Image result for cyes we can write inside the main function.That is we can pass formal arguments inside the main function in c.we can declare any variable inside the main function which is same as declaring the variable inside the block of the main function. lets have a look on the program given below:




Program:-  

#include <stdio.h>
#include <stdlib.h>

int main(int a,int b)
{
    int c;
    printf("\"enter the two numbers\"");
    scanf("%d%d",&a,&b);
    c=a+b;
    printf("the sum of %d and %d is %d",a,b,c);
    getchar();
    return 0;
}

Have A Try:-

Can we Store Something in the void Data Type.If no then what is the purpose of using void as a modifier or a data type in "C Programming" languages.put your answer in the form of the comment.

you many also contact us at contact us
Email:-      admin@allaboutcomputing.net
Read More

Write a C program for Generating a pattern as given bellow

Posted by Tushar Bedekar
A B C D E F G F E D C B A
A B C D E F     F E D C B A
A B C D E            E D C B A
A B C D                   D C B A
A B C                           C B A
A B                                   B A
A                                          A






C Program me:-


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int l=6;
    int i,k,p=6,m=1;
    char ch,kp='F',tu;
    printf("ABCDEFGFEDCBA \n");
    for(i=0;i<=6;i++)
    {
        tu=kp;
        ch=('A'-1);
        for(k=0;k<l;k++)
        {
            ch=ch+1;
            printf("%c",ch);
        }

        for(k=0;k<m;k++)
            printf(" ");

        for(k=0;k<p;k++)
        {
           printf("%c",tu);
           tu=tu-1;
        }
        kp=kp-1;
        printf("\n");
        l=l-1;
        m=m+2;
        p=p-1;
    }

    return 0;
}

Read More

IDE,Linker,Editor,Console And Debugger

Posted by Tushar Bedekar
Basically If We talk About writing the "C Program-me" We usually use the IDES (Integrate Development Environment) such as Turbo C++,Dos box(specially for windows 7 and windows 8). More over one can also use online software's to compile and execute the c program-me.


Integrated Development Environment IDE:-


Basically place that we use to write the "C program-me" is referred to as the Integrated development environment (IDE).An integrated development environment (IDE) or interactive development environment is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, build automation tools and a debugger. Most modern IDEs offer Intelligent code completion features.


Linker:-



A linker or link editor is a computer program that takes one or more object files generated by a compiler and combines them into a single executable program.

Definition: To convert Source Code to Machine code takes two phases.
Compilation. This turns the Source Code into Object Code.
 Linking. This collects all the various Object Code files and builds them into an EXE or DLL.
Linking is quite a technical process. The obj files generated by the compiler include extra information that the linker needs to ensure that function calls between different obj files are correctly "joined up".


Editor:-



A text editor is used to edit plain text files.  Text editors differ from word processors, such as Microsoft Word or WordPerfect, in that they do not add additional formatting information to documents.  You might write a paper in Word, because it contains tools to change fonts, margins, and layout, but Word by default puts that formatting and layout information directly into the file, which will confuse the compiler.  If you open a .doc file in a text editor, you will notice that most of the file is formatting codes.  Text editors, however, do not add formatting codes, which makes it easier to compile your code.

Definition: 
An Editor is an program much like a Word Processor that you use to edit the Source Code of any program you write.

Most IDEs come with a built in editor and some will automatically highlight compile errors in the editor to simplify fixing them.


Console:-



(1) The combination of display monitor and keyboard (or other device that allows input). Another term for console is terminal. The term console usually refers to a terminal attached to a minicomputer or mainframe and used to monitor the status of the system.
(2) Another term for monitor or display screen.
(3) A bank of meters and lights indicating a computer's status, and switches that allow an operatorto control the computer in some way.
(4) A device specially made for game play called a video game console. The player interacts with the game through a controller, a hand-held device with buttons and analog joysticks or pads. Video and sound are received by the gamer though a television. See also console game.
(5) In Windows Home Server the Console is the application software you use to manage Windows Home Server from any of the computers on your home network. Here you can configure back-ups, access add-ins, configure folders, and change Windows Home Server settings.


Debugger:-



A special program used to find errors (bugs) in other programs. A debugger allows a programmer to stop a program at any point and examine and change the values of variables.

Most IDEs come with a built in editor and some will automatically highlight compile errors in the editor to simplify fixing them.


Read More

Top 20 "C" programs asked in interview.

Posted by Unknown

Programs :


1. Write a program to find factorial of the given number...
2. Write a program to check whether the given number is even or odd.
3. Write a program to swap two numbers using a temporary variable.
4. Write a program to swap two numbers without using a temporary variable.
5. Write a program to swap two numbers using bit wise operators.
6. Write a program to find the greatest of three numbers.

7. Write a program to find the greatest among ten numbers.
8. Write a program to check whether the given number is a prime.
9. Write a program to check whether the given number is a palindrome c number.
10.Write a program to check whether the given string is a palindrome .
11.Write a program to generate the Fibonacci series.
12.Write a program to print"Hello World"without using semicolon anywhere in the code.
13.Write a program to print a semicolon without using a semicolon anywhere in the code.
14.Write a program to compare two strings without using strcmp() function.
15.Write a program to concatenat e two strings without using strcat() function.
16.Write a program to delete a specified line from a text file.
17.Write a program to replace a specified line in a text file.

18.Write a program to find the number of lines in a text file..
19.Write a C program which asks the user for a number between 1 to 9 and shows the number. If the user
inputs a number out of the specified range, the program should show an error and prompt the user for a
valid input.
20.Write a program to display the multiplication table of a given number..



Note:-

  • The Solution to the above question will be uploaded soon
  • The above question are as per the author point of view.the real questions may be different.

Read More

Top 20 Frequently asked questions in c programming

Posted by Tushar Bedekar

Top 20 "C" programs asked in interview,,.!!!

Programs :

1. Write a program to find factorial
of the given number...
2. Write a program to check whether the given number is even or odd.
3. Write a program to swap two numbers using a temporary variable.
4. Write a program to swap two numbers without using a temporary variable.
5. Write a program to swap two numbers using bitwise operators.
6. Write a program to find the greatest of three numbers.
7. Write a program to find the greatest among ten numbers.
8. Write a program to check whether the given number is a prime.
9. Write a program to check whether the given number is a palindrome c number.
10.Write a program to check whether the given string is a palindrome .
11.Write a program to generate the Fibonacci series.
12.Write a program to print"Hello World"without using semicolon anywhere in the code.
13.Write a program to print a semicolon without using a semicolon anywhere in the code.
14.Write a program to compare two strings without using strcmp() function.
15.Write a program to concatenat e two strings without using strcat() function.
16.Write a program to delete a specified line from a text file.
17.Write a program to replace a specified line in a text file.
18.Write a program to find the number of lines in a text file..
19.Write a C program which asks the user for a number between 1 to 9 and shows the number. If the user
inputs a number out of the specified range, the program should show an error and prompt the user for a
valid input.
20.Write a program to display the multiplica tion table of a given number..

Note:-The solution will be published shortly stay connected with us.
Read More

Pointers in C and C++

Posted by Tushar Bedekar
The correct understanding and use of pointers is crucial to successful C programming. There are several reasons for this: First, pointers provide the means by which functions can modify their calling arguments. Second, pointers support dynamic allocation. Third, pointers can improve the efficiency of certain routines. Finally, pointers provide support for dynamic data structures, such as binary trees and linked lists.
Pointers are one of the strongest but also one of the most dangerous features in C. For example, a pointer containing an invalid value can cause your program to crash. Perhaps worse, it is easy to use pointers incorrectly, causing bugs that are very difficult to find. Because of their importance and their potential for abuse, this chapter examines the subject of pointers in detail.

What Are Pointers?

A pointer is a variable that holds a memory address. This address is the location of another object (typically another variable) in memory. For example, if one variable contains the address of another variable, the first variable is said to point to the second. 


Pointer Variables

If a variable is going to be a pointer, it must be declared as such. A pointer declaration consists of a base type, an *, and the variable name. The general form for declaring a pointer variable is
type *name;
where type is the base type of the pointer and may be any valid type. The name of the pointer variable is specified by name.
The base type of the pointer defines the type of object to which the pointer will point. Technically, any type of pointer can point anywhere in memory. However, all pointer operations are done relative to the pointer's base type. For example, when you declare a pointer to be of type int *, the compiler assumes that any address that it holds points to an integer— whether it actually does or not. (That is, an int * pointer always ''thinks" that it points to an int object, no matter what that piece of memory actually contains.) Therefore, when you declare a pointer, you must make sure that its type is compatible with the type of object to which you want to point.

The Pointer Operators

There are two pointer operators: * and &. The & is a unary operator that returns the memory address of its operand. (Remember, a unary operator only requires one operand.) For example,
m = &count;
places into m the memory address of the variable count. This address is the computer's internal location of the variable. It has nothing to do with the value of count. You can think of & as returning "the address of." Therefore, the preceding assignment statement can be verbalized as "m receives the address of count."
Image result for pointer in cTo understand the above assignment better, assume that the variable count uses memory location 2000 to store its value. Also assume that count has a value of 100. Then, after the preceding assignment, m will have the value 2000.
The second pointer operator, *, is the complement of &. It is a unary operator that returns the value located at the address that follows. For example, if m contains the memory address of the variable count,
q = *m;
places the value of count into q. Thus, q will have the value 100 because 100 is stored at location 2000, which is the memory address that was stored in m. You can think of * as "at address." In this case, the preceding statement can be verbalized as "q receives the value at address m."

note:-These are the basic things that we have discussed today for more articles on pointer stay connected with us.

For any kind of doubts feel free to ask on contact us
     
Read More

Tic-Tac Toe Game using C Programming

Posted by Tushar Bedekar

/* A simple Tic Tac Toe game. */

#include <stdio.h>
#include <stdlib.h>

char matrix[3][3];                   /* the tic tac toe matrix */       
char check(void);
void init_matrix(void);
void get_player_move(void);
void get_computer_move(void);
void disp_matrix(void);
int main(void)
{
char done;
printf("This is the game of Tic Tac Toe.\n");
printf("You will be playing  against the computer.\n");
done = ' ';
init_matrix();
do{
disp_matrix();
get_player_move();
done = check();                                                               /* see if winner */
if(done!= ' ') break;                                                       /* winner!*/
get_computer_move();
done = check();                                      /* see if winner */
} while(done== ' ');
if(done=='X') printf("You won!\n");
else printf("I won!!!!\n");
disp_matrix();                                          /* show final positions */
return 0;
}

/* Initialize the matrix. */

void init_matrix(void)
{
int i, j;
for(i=0; i<3; i++)
for(j=0; j<3; j++) matrix[i][j] = ' ';
}

/* Get a player's move. */

void get_player_move(void)
{
int x, y;
printf("Enter X,Y coordinates for your move: ");
scanf("%d%*c%d", &x, &y);
x--; y--;
if(matrix[x][y]!= ' '){
printf("Invalid move, try again.\n");
get_player_move();
}
else matrix[x][y] = 'X';
}

/* Get a move from the computer. */

void get_computer_move(void)
{
int i, j;
for(i=0; i<3; i++){
for(j=0; j<3; j++)
if(matrix[i][j]==' ') break;
if(matrix[i][j]==' ') break;
}
if(i*j==9) {
printf("draw\n");
exit(0);
}
else
matrix[i][j] = 'O';
}

/* Display the matrix on the screen. */

void disp_matrix(void)
{
int t;
for(t=0; t<3; t++) {
printf(" %c | %c | %c ",matrix[t][0],
matrix[t][1], matrix [t][2]);
if(t!=2) printf("\n---|---|---\n");
}
printf("\n");
}

/* See if there is a winner. */

char check(void)
{
int i;
for(i=0; i<3; i++)                                                    /* check rows */
if(matrix[i][0]==matrix[i][1] &&
matrix[i][0]==matrix[i][2]) return matrix[i][0];
for(i=0; i<3; i++)                                                   /* check columns */
if(matrix[0][i]==matrix[1][i] && matrix[0][i]==matrix[2][i])
    return matrix[0][i];
/* test diagonals */
if(matrix[0][0]==matrix[1][1] &&
matrix[1][1]==matrix[2][2])
return matrix[0][0];
if(matrix[0][2]==matrix[1][1] &&
matrix[1][1]==matrix[2][0])
return matrix[0][2];
return ' ';
}


Download Game:-

                                                           


Read More

INTERVIEW QUESTIONS IN "C PROGRAMMING "LANGUAGE

Posted by Tushar Bedekar


TABLE OF CONTENTS

CHAPTER 1: Variables & Control Flow

1. What is the difference between declaring a variable and defining a variable? 
2. What is a static variable? 
3. What is a register variable? 
4. Where is an auto variable stored? 
5. What is scope & storage allocation of extern and global variables? 
6. What is scope & storage allocation of register, static and local variables?
7. What are storage memory, default value, scope and life of Automatic and Register storage class? 
8. What are storage memory, default value, scope and life of Static and External storage class? 
9. What is the difference between 'break' and 'continue' statements?
10. What is the difference between 'for' and 'while' loops?

solution:-Download link


CHAPTER 2: Operators, Constants & Structures


1. Which bitwise operator is suitable for checking whether a particular bit is ON or OFF? 
2. Which bitwise operator is suitable for turning OFF a particular bit in a number? 
3. What is equivalent of multiplying an unsigned int by 2: left shift of number by 1 or right shift of number by
1? 
4. What is an Enumeration Constant?
5. What is a structure? 
6. What are the differences between a structure and a union? 
7. What are the advantages of unions? 
8. How can typedef be to define a type of structure? 
9. Write a program that returns 3 numbers from a function using a structure. 
10. In code snippet below: 
struct Date {
 int yr;
 int day;
 int month;
} date1,date2;
date1.yr = 2004;
date1.day = 4;
date1.month = 12;
Write a function that assigns values to date2. Arguments to the function must be pointers to the
structure, Date and integer variables date, month, year. 

solution:-Download link

CHAPTER 3: Functions


1. What is the purpose of main() function? 
2. Explain command line arguments of main function? 
3. What are header files? Are functions declared or defined in header files ? 
4. What are the differences between formal arguments and actual arguments of a function? 
5. What is pass by value in functions? 
6. What is pass by reference in functions? 
7. What are the differences between getchar() and scanf() functions for reading strings? 
8. Out of the functions fgets() and gets(), which one is safer to use and why? 
9. What is the difference between the functions strdup() and strcpy()? 

solution:-coming-soon


CHAPTER 4: Pointers


1. What is a pointer in C? 
2. What are the advantages of using pointers? 
3. What are the differences between malloc() and calloc()? 
4. How to use realloc() to dynamically increase size of an already allocated array? 
5. What is the equivalent pointer expression for referring an element a[i][j][k][l], in a four dimensional array?
6. Declare an array of three function pointers where each function receives two integers and returns float. 
7. Explain the variable assignment in the declaration
int *(*p[10])(char *, char *);
8. What is the value of 
sizeof(a) /sizeof(char *)
in a code snippet:
char *a[4]={"sridhar","raghava","shashi","srikanth"};
9. (i) What are the differences between the C statements below: 
char *str = "Hello";
char arr[] = "Hello";
(ii) Whether following statements get complied or not? Explain each statement. 
arr++;
*(arr + 1) = 's';
printf("%s",arr);

solution:-coming-soon


CHAPTER 5: Programs


1. Write a program to find factorial of the given number. 
2. Write a program to check whether the given number is even or odd. 
3. Write a program to swap two numbers using a temporary variable. 
4. Write a program to swap two numbers without using a temporary variable. 
5. Write a program to swap two numbers using bitwise operators. 
6. Write a program to find the greatest of three numbers. 
7. Write a program to find the greatest among ten numbers. 
8. Write a program to check whether the given number is a prime. 
9. Write a program to check whether the given number is a palindromic number. 
10.Write a program to check whether the given string is a palindrome. 
11.Write a program to generate the Fibonacci series. 
12.Write a program to print "Hello World" without using semicolon anywhere in the code. 
13.Write a program to print a semicolon without using a semicolon anywhere in the code. 
14.Write a program to compare two strings without using strcmp() function. 
15.Write a program to concatenate two strings without using strcat() function. 
16.Write a program to delete a specified line from a text file. 
17.Write a program to replace a specified line in a text file. 
18.Write a program to find the number of lines in a text file. 
19.Write a C program which asks the user for a number between 1 to 9 and shows the number. If the user inputs a number out of the specified range, the program should show an error and prompt the user for a valid input. 
20.Write a program to display the multiplication table of a given number.

solution:-coming-soon
Read More

Try If You Can

Posted by Tushar Bedekar




  • Note:- You Can Also Mail Your Responses at Contact us
  • The responses May be Generated either using GCC or Turbo C compiler.It does`t matter but the correctness of responses is required.
  • Download Turbo C HERE
  • Online Compiler HERE

Read More

Algorithms and Flowchart in C Programming

Posted by Tushar Bedekar
                              

                                           Algorithms:-
A sequential solution of any program that written in human language,called algorithm.
Algorithm is first step of the solution process, after the analysis of problem, programmer write the algorithm of that problem.
Example of Algorithms:
Q. Write a algorithms to find out number is odd or even?
Ans. 
step 1 : start
step 2 : input number
step 3 : rem=number mod 2
step 4 : if rem=0 then
               print "number even"
           else
               print "number odd"
           end if
step 5 : stop



                                            Flowchart:-

1. Graphical representation of any program is called flowchart.

2. There are some standard graphics that are used in flowchart as following:








Q. Make a flowchart to input temperature, if temperature is less than 32 then print "below freezing" otherwise print  "above freezing"?
Ans.










Read More
back to top