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

Which data structure is Best for library management system wheater Tree or Linked list?

It depends on what you intend to do with the data. The assumption is the data is dynamic, the number of elements are not known in advance. Binary trees are best if you want to sort the data as it is entered. Linked lists are best if you simply want a list of sequential data, or need to implement a stack or a queue.

What is the header file for gotoxy in c?

There is no such function as gotoxy(). It was originally a standard function in conio.h, used to set the console cursor position, but it was deprecated because it was non-portable. While it may still exist in older C compilers, its usage would be frowned upon today and no known C or C++ compiler should support such a function these days.

You are free to "roll your own" version of the function, of course. The following version works on Windows only. But given how little it actually adds to what already exists, and its non-portable nature it hardly seems worthwhile.

#include <stdio.h>

#include <conio.h>

#include <windows.h>

// Standard version:

void gotoxy( COORD c )

{

SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), c );

}

// Overloaded version emulating original gotoxy function:

void gotoxy( int x, int y )

{COORD c;c.X = x;c.Y = y;

gotoxy( c ); // call standard version

}

Write programme for sum of number given?

// this v'll work to obtain sum of 1st and last number of any number

#include

int main()

{

int num,sum=0,i,fd,ld;

printf("enter the number);

scanf("%d",&num);

ld=n%10; //will get the last digit

while(num!=0)

{

fd=n;

n/10; //to get the 1st digit

}

sum=fd+ld; //add 1st n last digit

printf("\n sum of 1st n last digit is %d",sum)

}

The depth of a complete binary tree with n nodes is-?

The number of elements in a complete, balanced, binary tree is N = 2D - 1, where D is the depth. Simply solve for D...

N = 2D - 1

N + 1 = 2D

log2 (N + 1) = D

Why null values in database?

The 'null'-content of any given field is just that. It's a 'nothing'. Example, if you create a database to hold chemical values for instance. If the values are, for example, real nubers. That would imply that any value that has 0 in it, is just that; zero. It was beeing measured, and found to contain zero. On the other hand if a value was not tested, the value of that compound should be set to 'null'. If a 'null' value isn't supported by the database a workaround is to set 'null' values to -1 (as per the example above). --

C program to calculate average using while loop?

//to calculate using while

#include<stdio.h>

#include<conio.h>

void main()

{ int count

float average,sum;

sum=0;

count=0;

while(count<N)

scanf("%f",n)

sum=sum+count

count=count+1

}

average=sum/n

Advantages and disadvantages of the programming language FORTRAN?

Up till Fortran 90/95, the language was primarily intended for calculations. It remains one of the best computational languages ever developed, and is still in heavy use in the financial industry.

However, due in large part to disagreements among members of the Fortran development groups, Fortran 77 was deficient in a number of areas. Most or all of these have since been addressed by Fortran 90/95, however, so they do not represent current language deficiencies. These limitations included:

  1. Poor string handling, including weak concatenation and length functions.
  2. Subroutines pass arguments by reference rather than by value, making data protection difficult.
  3. Data scoping is limited. Variables can either be local or in COMMON blocks, but no other scoping is allowed. As a result, it's not possible to write file-level procedures; shared logic must be in a separate subroutine or repeated via cloning.
  4. Loop controls are somewhat limited, requiring continued use of the GOTO statement to manage flow in some cases.

Is the for loop a pretest type of loop?

Pretest loops, such as for-loop, while-loop, execute/evaluate the condition statement first, if the condition is met, then the statements of the loop are executed. If you were referring to the body of the loop being carried out at least once, no, the body will not be touched if the condition fails (pre-test, test BEFORE the [next] execution of the body). But the condition of the loop must have been evaluated at least once.

In contrast to the post-test loops, such as do-while, repeat-until, the condition is evaluated AFTER the [next] execution of the body. It is possible that the condition is never evaluate, and not the entire loop body being executed.

What is readability as a criteria of evaluating programming languages?

Yes. Some computer languages, such as VB, VB.NET, COBOL are designed for business, while Fortran is for engineers and scientists.

Which one is better between Compiler and interpreter?

A compiler is a program that takes a programming language like that of java and then translates it into computer language for the software user. The interpreter just ( just like that of a human interpreter) takes the foreign language which would be that of the programming language and turns it into the machine code. Both of these programs take a high-level programming language and translates them into the machine code, but the interpreter is slower to translate than the compiler because of the fact it processes and interprets each statement many times.

When will lvalue error occur in c?

When there is no addressable value in program, then compiler will give lvalue error.

Lvalue or location value is an address that is stored into while rvalue is the "read" value, ie., value of a constant or the value stored at a location. In the assignment a = 31; we have the lvalue of a used on the left hand side and the integer contant value 31 assigned to this location. In the assignment b = a; we have the rvalue of a (31) used to assign to the lvalue of b . So depending on which side of an assignment, we use the variable a , we get two different behaviors

What is Queue Explain its Operations with example?

A queue is a first in, first out (FIFO) data structure. Queues are typically used to buffer data between an input and an output device, particularly when the input and output devices operate at different frequencies. Typically one thread controls incoming data, pushing data onto the queue structure. Meanwhile another thread pops the first element from the queue and processes it. To prevent data races (where both threads update the queue concurrently) the push and pop operations are mutually exclusive. In order to perform a push or pop, a thread must first acquire a lock. If the lock is already held by another thread, the current thread is blocked. A blocked thread will yield to other threads and attempt to hold the lock on its next time-slice. Meanwhile, the thread that holds the lock can push or pop an element from queue, releasing the lock as soon as it has completed the operation.

Queues are typically implemented using a singly-linked circular list. New elements are pushed onto the tail while existing elements are popped from the head. Constant-time access to both the head and tail is achieved through a single pointer to the tail, which points "forwards" to the head.

Program to find factorial of a number using recursion?

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

int i=1,fact=1,n;

printf("enter a no.");

scanf("%d"n);

while(i<=n)

{

fact=i*fact;

i++;

}

printf("factorial=%d",fact);

getch();

}

What do you mean by declaration not allowed here in C programming?

Declarations aren't allowed everywhere; you've found a place (after an executable statament, most likely), where a declaration cannot be put.

How is an one dimensional array is represented in memory?

Arrays are allocated as a contiguous block of memory divided into one or more elements of equal size and type. Knowing the start address of the array makes it possible to reference any element within the array through a zero-based index. Multiplying the index by the size of an element determines the offset from the start of the array.

How structure is passed to function using structure pointer?

When you pass an object to a function you are not actually passing the object, you are only passing the object's value. This is what is meant by the term pass by value.

When passing a value to a function there are actually two objects involved in the exchange: the actual argument (the object that is being passed) and the formal argument (the object used by the function). When we call a function that accepts one or more arguments (also known as parameters), the value of the actual argument is assigned to the corresponding formal argument. Thus the formal argument is a copy of the actual argument and any changes made to the formal argument will have no effect upon the actual argument.

When the formal argument is a pointer, however, the value we pass is a memory address. The actual argument can either be a pointer of the same type or we can take the address of an object of the same type using the address-of operator and pass that. Either way, the value we pass is a memory address. We call this pass by reference even though the address is actually being passed by value. Passing by reference means that the formal argument and the actual argument both refer to the same object and offers an efficient means of passing large objects that are too expensive to copy. This includes most structures and unions and all arrays. Note that arrays implicitly decay to pointers and therefore cannot be passed by value. Structures and unions can be passed by value, but if they are larger than a pointer (in bytes) passing by reference is more efficient.

There are four different ways to declare a formal argument as a pointer:

  1. mutable pointer to mutable type
  2. mutable pointer to constant type
  3. constant pointer to mutable type
  4. constant pointer to constant type

Ideally, functions should declare formal pointer arguments using methods 2 or 4. Both point to constant types so this gives the caller an assurance that the function has no side effects upon the object being passed by reference. Functions that use methods 1 or 3 should be regarded as having side-effects upon the object being referred to. This can be desirable for efficiency reasons, however returning values via arguments (also known as output parameters) should be avoided whenever possible.

Note that it makes no difference if the formal pointer argument is mutable or constant because the formal and actual arguments are still separate objects. Constant formal arguments are only of relevance to the function designer, they are of no importance to the caller. This is true of all values passed to functions whether the value is a memory address or not. What is important to the caller of a by reference function is whether or not the object being pointed at is declared constant or not.

How do you write a c program using functions and array?

Eg:

int main (int argc, char **argv)

{

int i;

printf ("array argv has %d elements:\n", argc);

for (i=0; i

return 0;

}

What is fflush?

The fflush() function writes any buffered data to the specified file stream. When you write data to a file (with a function such as fprintf()), it is actually placed in a memory buffer. The data is only actually written to the file when the buffer is full, the file stream is closed or when fflush() is called.

How do you create a program to store number in array and to find the avg of the number using c plus plus?

#include

using std::cin;
using std::cout;
using std::endl;

int main()
{
const int numOfElements = 5;//defines how many elements are in your array
double arr[numOfElements] = {0.0};
cout << endl << "Enter " << numOfElements << " for your array";
for (int i = 0; i < numOfElements; i++)
{
cout << endl << (i + 1) << " element: ";
cin >> arr[i];
}

double sum = 0.0;
for (int i = 0; i < numOfElements; i++)
{
sum += arr[i];

}

cout << endl << "Average is: " << (sum/numOfElements) << endl;

system("PAUSE");
return 0;

}

Why was C programming invented?

Writing operating systems like Unix/Linux and a large part of Windows 3.1 (not sure about later versions of Windows) although some of Windows 3.X was done in Pascal.

Most of the Operating systems used these days are developed using C.

Actually the kernel of the OS is written in C and kernel is the base of any OS

How to excute c program on dos?

Command-line and IDE C compilers: There are two types of C compilers, each of which has advantages and disadvantages: (i) Command-line C compilers and (ii) IDE or Windows C compilers To compile and run a C program using a command-line C compiler, you have to go through the following steps: (i) Write the C program (call it ``myfile.c'') in a text editor or word processor (for example, the simple ``Hello'' program below), (ii) Save it as a file on your computer's hard disk, (iii) ``Compile it'' to a computer-executable program by entering a compile command at a command prompt, for example for the following C compiler programs: gcc -Wall -o myfile myfile.c (using the GNU C compiler, UNIX or Microsoft Windows) cl myfile.c (Microsoft Visual C++ command-line compiler) bcc32 myfile.c (Borland C/C++ compiler, Microsoft Windows) followed by the ``Enter'' key, and finally (iv) Run the program by entering myfile at a command prompt, again followed by ``Enter''. If you want to save the output of ``myfile'' as a text file ``myfile.txt'', enter instead myfile > myfile.txt

Indentation is used to make programming code easier to read?

To make the code easier to read for you and other programmers that might view your work.