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

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.

    String In JAVA language?

    In Java, literal character strings such as "foo" are implemented as instances of the String class. These strings are constant and can not be modified directly. Mutable character strings, or string variables, are implemented as instances of StringBuffer class. It is also possible to work directly with arrays of chars, but String and related classes offer lots of useful methods.

    What is the difference between malloc and new other than syntax?

    Click on the link to your right for the answer.

    Answerboth malloc and new functions are used for dynamic memory allocations and the basic difference is: malloc requires a special "typecasting" when it allocates memory for eg. if the pointer used is the char pointer then after the processor allocates memory then this allocated memory needs to be typecasted to char pointer i.e (char*).but new does not requires any typecasting. Also, free is the keyword used to free the memory while using malloc and delete the keyword to free memory while using new, otherwise this will lead the memory leak. AnswerBesides the basic syntactical difference: malloc is a C function which will allocate the amount of memory you ask and that's it. new is a C++ operator which will allocate memory AND call the constructor of the class for which's object memory is being allocated.

    Similarily, free is a C function which will free up the memory allocated. but delete is a C++ operator which will free up the allocated memory AND call the destructor of the object.

    Answermalloc in a function and new is an operator, and its a good programming practice to use an operator instead of functions, because function itself requires some time to be executed whenever that particular function is called. so the main difference is that we use operators instead of malloc because of the TIME CONSTRAINT. Answer1.malloc requires the type casting during decleration , where as new doesn't needed the type casting during decleration 2. when ever we use new for allocating memory along with this it calls the constructor of the class for which object memory is allocated 3. in case of malloc free is the word used to clear the memory, where as delete is the format used in case of new to free the memory after usage 4. malloc is function, where as new is operator..so the time required for execution is less in case of new (it being a operator) as compared to malloc(it being a function) Answer1. malloc is a function call, while new is an operator. This difference is syntactic; behind the scenes, they both perform pretty much the same work to allocate the memory, and operator new also invokes any required constructors. There is a commonplace urban myth that operators are somehow faster in your code than functions; this is not correct, as any operator (except for mathematical operations that correspond directly to a single machine-code instruction) invocation amounts to a function call in any case. 2. malloc can fail, and returns a NULL pointer if memory is exhausted. Operator new never returns a NULL pointer, but indicates failure by throwing an exception instead. There is also a nothrow() version of operator new, which does return NULL on failure.

    How do you write a program to find the length of a string?

    /* with run-time library */

    int len;

    char* str;

    len = strlen (str);

    /* without run-time library */

    int mystrlen (const char* str) {

    int len;

    while (*str != '\0') {

    len++;

    str++;

    }

    return len;

    }

    int len;

    char* str;

    len = mystrlen(str);

    How garbage is collected?

    Yes, GC can be considered as a JVM utility that checks the status of memory objects and cleans up all unused memory references so that, this memory can be used by other objects.

    What is far and near pointer and how are they used?

    It is a matter of the memory model you are using. On old or embedded systems, some memory was outside of the range of a normal pointer. If you have 4 megs of ram you need at least a 22bit pointer to see all of it. But let's say you only have a 16 bit pointer. This means you can only access the first 65K of ram. Odd as it may sound, this was a problem on old computers, and is sometimes an issue on embedded devices with limited processing power. The near and far classifications were a solution. Pointers are near by default. In my example above, the 65K of ram would be accessed with a near pointer. To get past that 16 bit limit, you need a far pointer. Thus: memory within the pointer's range is near. Memory outside of the range is far. Near pointer: char near * ptr; Far pointer: char far * ptr;
    A far pointer uses both the segment and the offset address to point to a location in memory. A near pointer in contrast uses only the offset address and the default segment. The far pointer can point to any location in memory, whereas the near pointer can only point to a nearby local address.
    Something that was important 20 years ago. Now you can forget it.