answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

How to write a program to implement a binary search tree in C?

struct node{

int data;

struct node *left, *right;

};

typedef struct node node;

non recursive method :

main()

{

node * root = NULL , *new = NULL *temp1 =NULL , * temp2 = NULL;

int num =1;

printf(" Enter the elements of the tree( enter 0 to exit)\n");

while(1)

{

scanf("%d", &num);

if(num==0)

break;

new = malloc(sizeof(node));

new->left = new->right = NULL;

new->data = num;

if( root NULL)

root->left = new;

else

insert( new,root->left);

}

}

C program to print number in reverse order?

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int r=0,d,m,n;

printf("Enter a value=");

scanf("%d",&n);

m=n;

do

{

d=m%10;

m=m/10;

r=(r*10)+d;

}

while(m!=0);

printf("%d is the reverse",r);

getch();

}

What is the purpose of the dereference operator when used with a pointer variable?

Data type is mandatory in every variable-declaration.

Example:

int i; -- integer

int *pi; -- integer-pointer

int ai[10]; -- integer-array

int *api[10]; -- array of integer-pointers

int (*api)[10]; -- pointer to integer-array

Difference between library file and header file?

EX: pgm

#include<stdio.h>

main()

{

printf("haiii");

}

Header file:

(1) contains the function(printf) declaration

(2) during preprocessing, the printf function is replaced by the function declaration

Library file :

(1) contains the function(printf) definition

(2) during linking, the function declaration is replaced with the function definition.obviously, everything will be in object while linking

What do you understand by the word indentation in programming language?

Indentation means to represent the coding in a readable format. for example:

void main()

{

int i=0;

if(i==0)

{

printf("%c\n", 'A')

}

else

{

printf("%c\n", 'B')

}

getch();

}

the above program is not properly readable cause it don't have indentations like the below one

void main()

{

int i=0;

if(i==0)

{

printf("%c\n", 'A')

}

else

{

printf("%c\n", 'B')

}

getch();

}

don't go for what this program is doing, it's just an example.

What are the advantages and disadvantages of C language?

Advantages of C language

  1. Speed of the resulting application. C source code can be optimized much more than higher level languages because the language set is relatively small and very efficient.
  2. That leads to a second advantage that C has which is its application in Firmware programming (hardware). That is due to its ability to use/work with assembly and communicate directly with controllers, processors and other devices.
  3. C Programming language is very easier to learn. The main advantages of C language is that there is not much vocabulary to learn, and that the programmer can arrange for the program is very fast.

Disadvantages of C Language

  1. C does not have OOPS feature that's why C++ is developed. If you know any other modern programming language then you already know its disadvantages.
  2. There is no runtime checking in C language.
  3. There is no strict type checking (for example: we can pass an integer value for the floating data type).
  4. C doesn't have the concept of namespace.
  5. C doesn't have the concept of constructors and destructors.

What is the library function in c explain that?

education suportive, enhances good comm btwn users refreshing site

In computing terms, the term library also refers to an archive of functions, typically archived in binary (pre-compiled) form. This allows for easy re-use of previously defined, implemented and tested functionality, with possible protection of intellectual property when using a binary library.

C program for odd or even?

# include

void main()

{

int a;

printf("\n Enter a number to find if its odd or even");

scanf("%d",&a);

if(a%2==0)

{

printf("\n The number entered is even");

}

else

{

printf("\n The number entered is odd");

}

getch();

}

Describe why it is a bad idea to implement a link list version a queue which used the head of the list as the rear of the queue?

It isn't. In fact it is a very good idea. Since the list is circular, you need only maintain a reference to the tail (rather than the head), because the tail provides constant time access to both the head and the tail. In this way you get constant time insertions at the tail and constant time extractions at the head via a single reference -- exactly what you want from a queue. If the list were not circular, you would need two references, one to the head and one to the tail. That's a waste of memory when the tail has an otherwise redundant link that's always null. Point it at the head and refer to the tail instead of the head and you save memory.

What type of errors are reported by the compiler?

That depends on the language, and in part on the compiler. A good compiler can find lots of different errors, for example:

  • A variable that is used before being declared.
    • Type incompatibility.
    • A variable is used that hasn't been assigned a value before. (This would mean that any garbage that happened to be at that position in memory would be used, instead of using a known value.)
    • A variable is assigned a value, but that variable is never used. This would usually be only a warning - nothing bad would happen, but some lines in your program would be superfluous.
    • Array out of bounds - for example, an array has 5 elements, numbered 0-4, and you are trying to access element #5, or element # minus 1.
    • A mismatch between open and close parentheses, braces, if/endif, etc.
    • A function or method has been declared to return a certain data type, but in the return statement you return a different data type - or no data at all.

      And many more. If you do some programming, you will soon see the compiler catching all kinds of mistakes.

  • How do you write a program in Basic to display all the even numbers up to 100?

    In visual basic:

    Module Module1

    Sub Main()

    Dim Inst As Integer

    For Inst = 0 To 100 Step 2

    Console.WriteLine(Inst)

    Next

    End Sub

    End Module

    How does the for loop work in c?

    • For loop is "Counter controlled loop" i.e. a counter or control variable is used to process the for loop , as discussed in earlier chapters.
    • For loop is an "Entry controlled loop" i.e. the condition to iterate the loop must be check at the starting of the loop and loop body will not execute if the condition is False. Source website:

    http://codedunia.in/c-language/for-loop-in-c-programming.php

    What are the language design requirements for a language that supports abstract data types?

    What are language design requirements for languages that support abstract data types ----

    Is something that you will find in your text book or ask your teacher.

    WikiAnswers cannot do your homework for you.

    Write the program in c language for the addition of two matrices using pointer?

    #include<stdio.h> #include<conio.h> int main() { int n,m,i,j,k; int a[38][38],b[38][38],p[38][38]; printf("\nEnter the number of rows and coloumns "); scanf("%d %d",&n,&m); printf("\nEnter the elements of first matrix "); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",(*(a+i)+j)); } } printf("\nMatrix is "); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) { printf("%d",*(*(a+i)+j)); printf("\t"); } } printf("\nEnter the elements of second matrix "); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",(*(b+i)+j)); } } printf("\nMatrix is "); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) { printf("%d",*(*(b+i)+j)); printf("\t"); } } printf("\nAfter ");

    Write a c program to compare two strings without using builtin function?

    A string is a character array, so you can compare them one character at a time:

    String x = "test"

    String y = "test"

    for(int i = 0; i < x.length && i < y.length; i++)

    {

    if(x[i] != y[i])

    return false;

    }

    return true;

    What is mean by text and binary files used in c?

    A text file is a file containing human readable characters organized into records (lines) that are separated by the new-line character. The run-time library parses on this basis, and converts carriage-return/line-feed sequences to and from the new-line character as needed. (In a Windows/DOS environment.)

    A binary file is a file containing any characters. There is no file based delimiting - all record distinctions are made by the program. (The exception to this is in the IBM (and other?) family of MainFrame computers where logical record sizes are declared in the DCB, and the file is not processed in stream mode.)

    How tree can be represented using linked list?

    A tree is a linked list. Well, sort of... An ordinary linked list has one forward node pointer within each node, while a tree has more than one. Often, in a tree, there is a relationship between nodes, such as an ordering based on which sub-node pointer the current node is a child of.

    What is difference between loop and mesh?

    When your computer contains loop, they can repeat the same set of code a lot.

    The computer can repeat the code

    hundreds, even thousands, of times.it is used for increament

    *No

    *that's not at all what the question is asking

    *A "Mesh" is a small loop in a circuit. A "Loop" is a larger one, within containing several "Meshes".

    *Most places use them interchangeably

    What is the program language c?

    C is a pop language.

    C is a case sensetive language.

    C is motherof all language.

    C is block structure language.

    C is a high level language.

    C is advace of B language.

    C developed by D.richties in 1972 at AT & T Bell lab in USA.

    Sachin Bhardwaj

    986854722

    skbmca@gmail.com

    What are comments in a C program?

    Comments are user-defined remarks inserted into code to give the reader more information than is provided by the code alone. Comments are ignored by compilers.

    In C (and C++) there are two types of comment: single-line comments and multi-line comments. A single line comment begins with a double-slash (\\) and extends to the end of the line. A multi-line comment starts with a slash-asterisk (\*) and extends to the first occurrence of an asterisk-slash (*/). Multi-line comments need not extend across multiple lines, they can also be used to insert comments inside code on a single line.

    Note that outside of tutorial code, comments should never just repeat what the code does; the code itself tells you what it does, but it may not be clear why it is doing it. Comments should be brief and informative but should not distract the reader with any unnecessary detail.

    Is it necessary to give the size of array?

    Depends on the language. For C, no you don't. You can type blank brackets (int Arr[]) when declaring the array, or you can just use a pointer (int* Arr). Both will allow you to use the variable as an array without having to declare the specific size. Hope this answers your question.

    In Java, an array is an object, and one which is dynamically allocated space. The default constructor does not require a size be specified.

    What is mean void in c plus plus?

    Void means there is no data type. So if you have a void function it does not return a value (and attempting to do so will cause an error) whereas a non-void function (ex. int, long, String, bool, etc) will return a value of that type.

    How many types of sorting array in C programming?

    You can sort an array with any method you want, but there is a built-in qsort function, declared in stdlib.h (see the attached link).

    bubble sort, quick sort, insertion sort, merge sort, radix sort and lot more..

    merge sort is the most efficient one..

    How can we implement Leaky bucket algorithm in c?

    //here is a simple implementation of leaky bucket.

    #include<stdio.h>

    #include<stdlib.h>

    #include<dos.h>

    void main()

    {

    int i,packets[10],content=0,newcontent,time,clk,bcktsize,oprate;

    for(i=0;i<5;i++)

    {

    packets[i]=rand()%10;

    if(packets[i]==0) --i;

    }

    printf("\n Enter output rate of the bucket: \n");

    scanf("%d",&oprate);

    printf("\n Enter Bucketsize\n");

    scanf("%d",&bcktsize);

    for(i=0;i<5;++i)

    {

    if((packets[i]+content)>bcktsize)

    {

    if(packets[i]>bcktsize)

    printf("\n Incoming packet size %d greater than the size of the bucket\n",packets[i]);

    else

    printf("\n bucket size exceeded\n");

    }

    else

    {

    newcontent=packets[i];

    content+=newcontent;

    printf("\n Incoming Packet : %d\n",newcontent);

    printf("\n Transmission left : %d\n",content);

    time=rand()%10;

    printf("\n Next packet will come at %d\n",time);

    for(clk=0;clk<time && content>0;++clk)

    {

    printf("\n Left time %d",(time-clk));

    sleep(1);

    if(content)

    {

    printf("\n Transmitted\n");

    if(content<oprate)

    content=0;

    else

    content=content-oprate;

    printf("\n Bytes remaining : %d\n",content);

    }

    else

    printf("\n No packets to send\n");

    }

    }

    }

    }

    Write a program to find the reverse of a string in c using function?

    #include <stdio.h>

    #include <stdlib.h>

    void reverse(FILE * file) {

    int fscanf_return_value;

    char x;

    /* read a char */

    fscanf_return_value = fscanf(file,"%c",&x) ;

    if(fscanf_return_value == EOF) { //fscanf returns EOF as the END OF FILE

    return;

    }

    reverse(file); //Get the next char

    //do something with the char e.g. print

    putchar(x);

    return;

    }

    int main(int argc, char *argv[]) {

    int i;

    FILE *fd;

    if (argc!=2) {

    printf("Usage : \n %s FILENAME\n",argv[0]);

    exit(0);

    }

    if(!(fd=fopen(argv[1],"r"))) {

    printf("Opening file error\n");

    exit(1);

    }

    reverse(fd);

    printf("\n\n\t---\tenoD - Done\t---\n");

    close(fd);

    exit(0);

    }

    .....................if u like it get ask me more

    my FB ID is phani.9885120096@gmail.com.