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 do you check whether a character is numeric in an alphanumeric field in C?

If the character's ASCII value is in the range of the digit characters, then it is a numeric. In ASCII, the range of digits is from '0' to '9' (48 to 57 decimal). Note that character constants such as '0' will implicitly convert to the constant integer 48 (the ASCII code for the character) so there is no need to remember the actual value; the compiler can determine this for us.

The following function shows how one might test a character to see if it is a digit or not:

bool is_digit (const char c) {

return (c>='0' && c<='9');

}

The function will return true if the given character is a digit, otherwise it will return false.

What type of data uses FTP protocol?

FTP is the File Transfer Protocol, which can be used to transmit computer files from one computer to another. The files that are transmitted may contain any type of data, including executable machine code files. Typically, the files are compressed archives (such as ZIP or RAR files) to reduce the overall transmission times.

Would you select c plus plus or java in 11 class?

Its really a matter of opinion. I prefer C++ to Java but that doesn't mean C++ is always better than Java. C++ can be rather hard to learn if you are new to it but it is a very rewarding language. On the other hand, Java is very portable and is used in just about all Android phones (I don't know enough to say whether or not all of them use java.) Anyway, if it is system development or game development you are going for, C++ is a great choice, providing low level access to the computer and providing fast speed if the code is written well. Java is a good portable language that is compiled to computer code using the Java Virtual Machine which compiles it to computer readable code and then runs which makes it portable. In the case of Java, mobile phone apps, web apps and games (most well known being Minecraft) are available to you. It all depends on what you want, hopefully with the information I have give you you can make and informed decision.

Give atleast 5 real life examples of circular linked list?

Why do you think it is a question? It is a homework assignment.

What is the suitable programming language to run a real time process control system for a manufacturing plant?

Most programming languages can be used to write real time process control software. There are many that are specific to a manufacturer's range of process control modules and others that are generic real time languages. However, languages such as BASIC, Pascal, Python and dozens more have all been used successfully for real time processing. The nature of a process control demands that the language has good support of input and output but otherwise, most languages can handle most processing tasks with ease.

Perhaps the more important issue is the operating system. Windows, for example, is not designed for real time applications because of the large number of background and system tasks going on. In a system where response time is critical, it is a poor choice. Linux is regarded as a better choice as it is easier to configure background operation but it is still not an ideal real time operating system. LTLinux is better optimized for real time work and others include Lynx, VXworks, QSE and QNX.

How do you write a C plus plus program that creates and manipulates a dynamic one dimensional array storing a string entered by user without using any C plus plus Standard functions?

In short you cannot, unless you provide a suitable alternative to the standard library yourself (in other words, reinvent the wheel). At the very least you will need to include the common runtime definitions (crtdefs.h) just to create a bare-bones program that does absolutely nothing, but you'll need to implement all the standard IO functions yourself. Even third-party replacements make extensive use of the standard library, so you're completely on your own here. The standard library exists so that you can draw upon a rich set of primitive but highly optimised, tried and tested functions which act as building blocks upon which you can create your own programs.

How do you write a program to add 5 number?

Writing a program to add 5 numbers follows the same design principles as any other program design:

In the first step, clarify the requirements. For example, you might want to raise the following questions:

Will the program always add exactly 5 numbers, or any number of numbers up to 5?

Will all N summands be known at the same time, or will the program be required to add one summand at the time, until all N summands are accumulated?

Will all N summands share the same data type, and if so, what is the shared data type?

How is the program expected to handle summands of different types and resolution?

How is the program expected to obtain its input (the number N, and the N summands), and how is the program expected to present its output (the sum)?

How is the program expected to respond to error conditions?

In the second step, design a solution and identify its limitations. For example, you might discover that the algorithm stops functioning once the sum reaches a certain value. You might want to specify the precision of the result, and limitations of the algorithm (for example, the fact that N must be five).

In the third step, you'd repeat steps 1 and 2 until you understand the requirements, and the person who plans to use your program is satisfied with its limitations.

In the fourth step, you'd draft an initial version of the program. This could be feature limited (for example, with limited error checking), but should demonstrate that the core algorithm works correctly. Since the program will need to interface with a human or other programs, this version should also demonstrate this interface, proving that the required inputs and outputs can be obtained and delivered as intended.

In the fifth step, you'd refine your program. This will typically include refined error checking and diagnostics, performance improvements, etc.

In the sixth step, the program is being tested, and errors are addressed. When necessary, this might require returning to step 1.

In the seventh step, you should always review the requirements and limitations again to ensure that these agreed facts remain true, and no further limitations were added or new requirements discovered.

Subject to the complexity of your program, other steps include the creation of documentation and training materials, legal research, patent filing, software installation and distribution, protection of your intellectual property, and some-such.

What data type automatically increases each time a new record is entered?

There is no data type that automatically increases each time a new record is entered. You are probably thinking of a linked list, but that is not a data type, it is a container and it must be manually programmed to ensure correct behaviour. However, C does not provide object-oriented encapsulation so correct behaviour cannot be guaranteed. In C++, all containers are implemented as encapsulated objects, thus correct behaviour can be assured and the container can shrink and grow automatically.

What is the flowcharts of input three values and display largest number?

Input N1, N2, N3

Max = N1

If N2 > Max then Max = N2

If N3 > Max then Max = N3

Display Max

What is the difference between Ada cobol and c language?

It is something like the difference between ship, car and air-plane: they are hardly similar in any aspect.

What data type is unemployment rates?

Unemployment rates are typically expressed as a percentage of the total workforce. Thus the unemployment rate for any given locale is a real number (float, double or long double) in the closed range 0.0 through 100.0.

Which type of c program can be run on windows 7?

I guess you wanted to ask: why don't DOS-programs (like TurboC and programs generated by TurboC) run on Windows 7?

Answer: it is by design; unlike older versions, Windows 7 doesn't have a built-in DOS-emulator. Download and use DosBox.

How data structure can influence program performance?

Greatly.

Certainly, a person with data structures orientation will write better structure code.

Imagine yourself is asked to write adding to big integers numbers having 200 digits?

Using long also we can not do this.

By employing linked list type data structure we can achieve this.

This is an example only.

What is the difference between using a return value and a pass-by-reference parameter?

The main difference is that return values can be used in compound statements (such as assignments), whereas output parameters cannot. An output parameter is a non-const parameter that is passed by reference or as a pointer variable.

As a general rule, every function should return something through the return value, even if only an error level where zero would typically indicate success (but not always). A function that does not return anything (returns void) is not strictly a function, it is better described as a procedure. However, if a function can be guaranteed never to fail (provides trivial functionality) and has no need to return any other value to the caller, then returning void is a logical option. Just because a function should return a value doesn't mean that it must return a value.

However, the return value is limited by the fact that it only permits one value to be returned by a function. Output parameters allow a function to return several values at once and can be used in conjunction with the return value. If there is no need for the return value, it should be used to indicate the error level of the function wherever it would be appropriate. However it is not unusual for a function to accept a reference as an output parameter and to also return that same reference via the return value.

Note that although you could return multiple values via a struct or class type, this should only be considered if you have several functions that can make use of the struct or class type. However, in most cases it would be simpler to make those functions members of the struct or class itself.

What is the syntax to return a Pointer To A Character?

A function f() will can be defined as returning a pointer to a character with the syntax

char *f()

{

}

One must be careful in creating these functions that the character pointer is set to point to a static variable or an allocated string; an automatic variable will vanish when the function exits, leaving the pointer invalid.

I should point out that this is very basic C syntax. If this question is being asked as part of a school assignment, I must suggest that perhaps you should drop this course now, as it will be immeasurably harder as you get further into it.

Why compiler is not applicable in low level language?

In layman's terms, compiler is an application to convert the code into instructions computer can understand. In a low level language, the code is already written using low level instruction which a computer can understand. Hence there is no need for a compiler.

How you can draw an ellipse in C language?

The C language does not provide any support for graphics as standard. C is designed to be as generic as possible, but graphics are a system-specific feature. To use graphics in C you need a third-party graphics library that supports your operating system and hardware, however generic libraries such as OpenGL are available. Nevertheless, it is not possible to draw curves, you can only approximate a curve using a series of short lines. The shorter the lines and the higher the resolution, the smoother the curve will appear.

Assuming you have access to an OpenGL library, you can draw an ellipse as follows:

void DrawEllipse(float cx, float cy, float rx, float ry, int num_segments)

{

const float pi = atan (1) * 4;

float theta = 2 * pi / float (num_segments);

float c = cosf (theta);

float s = sinf (theta);

float x = 1;

float y = 0;

float t;

glBegin (GL_LINE_LOOP);

for (int i = 0; i < num_segments; ++i)

{

glVertex2 f (x * rx + cx, y * ry + cy);

t = x;

x = c * x - s * y;

y = s * t + c * y;

}

glEnd();

}

What would happen if you put too few elements in an array when you initialize it?

If the array does not have an initial size parameter, the array would be the size of the initialization vector, so you would not be able to store any data beyond the end of those elements without crashing your program or causing memory bugs. If there is a specified array size and the initialization vector is smaller than that size, then all remaining elements will be set to the value 0; it is not an error to not specify all elements in the initialization vector.

What is the basic difference between variables and data types in the c?

Variables are names given to the data. Data types are the kinds of data which the computer interacts with. In C there are five basic data types :

1)char (basically anything in ' '. Normally a single character)

2)int (all integers like -5 , 10 , -3201 etc)

3)float (any decimal value)

4)double (Higher decimal value)

5)void (nothing)

Consider the following statement

int var = 1;

The above statement means that you are declaring a variable var which is of data type int and giving the variable a value of 1.

How do you subtract improper fraction in C programming language?

The following shows how this can be achieved:

typedef struct fraction {

int n; // numerator

int d; // denominator

};

struct fraction subtract (struct fraction a, struct fraction b) {

struct fraction r; // result

r.d = lcm (a.d, b.d); // lowest common multiple

r.n = (a.n * (r.d/a.d)) - (b.n * (r.d/b.d));

return r;

}

The lcm() function has the following definition:

int lcm (int a, int b)

{

int sign = 1;

if (a<0) a*=-1, sign *=(-1);

if (b<0) b*=-1, sign *=(-1);

return (a*b) / gcd (a,b) * sign;

}

The gcd() function (greatest common divisor) has the following definition:

int gcd (int a, int b)

{ int sign = 1;

if (a<0) a*=-1, sign *=(-1);

if (b<0) b*=-1, sign *=(-1);

while (a!=b)

a>b?a-=b:b-=a;

return a * sign;

}