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 is ADT how it is different from class?

ADT stands for abstract data type. It is basically a set of data values and associated operations that are specifically independent in nature. Examples of adt are stacks,trees,lists(doubly,circular,etc) and so on. Class is a user defined data type which the user can use in implementing a stack ADT or tree ADT. Class is used for implementation as it provides data hiding and encapsulation which are the features of ADT in object oriented programming. Hope this helps!

What is the difference between proposition and predicate?

A proposition is a statement that is either true or false (its "truth value"). Example of a proposition: Belgium is a country in Europe. A predicate is a proposition whose truth depends on the value of one or more variables. Example of a predicate: x is a country in Europe. In this example, x is the variable, and the statement is true or false depending on what is chosen for x. For x=Belgium, the statement is true; for x=Egypt, it's false.

A predicate with one variable can be seen as a property, that is true or false of something, where the something is left open. A predicate with two (or more) variables can be seen as a relation between things, where the things are left open.

How did machines develop?

A machine is merely something that performs or assists in performing a task.

The simplest examples of machines are levers, pulleys, and wedges, all of which have probably been around in some form or another since before recorded history. So, I suppose no one really knows how they developed.

What distinguishes operators from other sort of functions?

Operators are a specific type of function that perform actions on operands, often involving mathematical or logical manipulation. Unlike general functions, which can simply map inputs to outputs, operators typically denote an operation (such as addition, subtraction, or logical conjunction) and can be unary (taking one operand) or binary (taking two operands). Additionally, operators often have specific syntax and precedence rules that dictate how they interact with each other in expressions.

How do you display the number of lineswordspunction markswhite space and digits in a text file?

You should have a separate variable to count each of those:

long nline, int npunct, nspace, ndigits;

...

printf ("%ld %ld %ld %ld\n", nline, int npunct, nspace, ndigits);

How can a called function determine the number of arguments that have been passed to it?

It is not the function but the compiler or interpreter which interprets the code. When the program is compiled and run the compiler checks the entire code line by line to check which function is called. If you encounter polymorphism in other Object Oriented Languages it would be more clear how a function with same name and different arguments are called.

Design iterative and recursive alogrithm to find the minimum among n elements?

// returns the minimum value in ns - iterative

public static final int findMinIterative(final int[] ns) {

if (ns.length == 0) {

return 0; // return 0 if ns is an empty array

}

// search each element of ns

int min = ns[0];

for (int i = 0; i < ns.length; ++i) {

// if an element smaller than min is found, store that as the new min

if (ns[i] < min) {

min = ns[i];

}

}

return min;

}

// returns the minimum value in ns - recursive

// Note that this problem does not lend itself to recursion; the solution is very similar to the iterative approach

public static final int findMinRecursive(final int[] ns) {

if (ns.length == 0) {

return 0; // return 0 if ns is an empty array

}

// start recursion

return findMinRecursive(0, ns[0], ns);

}

// recursive part of algorithm

private static final int findMinRecursive(final int i, final int min, final int[] ns) {

// bounds check

if (i >= ns.length) {

return min;

}

// recurse on next value of ns

return findMinRecursive(i + 1, Math.min(min, ns[i]), ns);

}

What is meant by the statement that training is extremely faddish?

Is the materials that is being taught to employees don't not line up employees schedule

C program to find sum of 'n' number using function?

void main ()

{

int no1, sum, n;

clrscr()

sum = 0;

n = 1;

printf("\n enter the number to which sum is to be generated");

scanf("%d",&no1);

while(n<=no1)

{

sum=sum+n;

n=n+1

}

printf("\n the sum of %d = %d, no1, sum");

getch ();

}

What is a loop in protein?

A loop in a protein refers to a flexible segment of the polypeptide chain that connects two secondary structure elements, such as alpha helices or beta sheets. Unlike the more rigid structures, loops can vary in length and conformation, allowing proteins to adopt diverse shapes and functions. They often play critical roles in protein-protein interactions, enzyme activity, and binding sites for ligands. Loops are essential for the dynamic nature of protein structure and function.

Write a C program to find lowest number among ten numbers using for loop?

If you had an array int numbers[10]; you would do it like this:

CODE:

int lowestnumber = numbers[0];

for(int i = 0; i < 10; i++){

if(numbers[i] < lowestnumber)

lowestnumber = numbers[i];

}

END CODE

I think this should work, and in the end the variable lowestnumber will hold the lowest value in the ten.

Hope this helps.

Write a program to find out transpose of a given matrix by using arrays?

#include<stdio.h> #include<conio.h> void main() { clrscr(); int m[10][10]; int i,j,r,c; for (i=0;i<10;i++) { for (j=0;j<10;j++) { m[i][j]=0; } } printf("\n Enter size of row and colomn:"); scanf("%d %d",&r,&c); printf("\n Enter the two matrices: \n"); for (i=0;i<r;i++) { for (j=0;j<c;j++) { printf("Enter element %d %d of m1: ",(i+1),(j+1)); scanf("%d",&m[i][j]); } } printf("\n The matrix is: \n"); for (i=0;i<r;i++) { for (j=0;j<c;j++) { printf("%d ",m[i][j]); } printf("\n"); } printf("\n The transpose of the matrix is: \n"); for (i=0;i<r;i++) { for (j=0;j<c;j++) { printf("%d ",m[j][i]); } printf("\n"); } getch(); }

Are there different types of friesians?

Yes there is, as a matter of fact. The most commonly known Friesian is the Holstien-Friesian diary cow. There are several different types: British, Dutch, German, Danish, Italian, Argentinian, Polish and Swedish. There also exists the American Beef Friesian.

The second Friesian is the Friesian horse, and there are also Friesian sheep.

How to declare near and far pointers in C?

It used to be a good question 30 years ago.

Right know you don't have to know anything about near and far pointers; but if you still use a 16-bit compiler, select 'Large Model' (or 'Huge Model'), and forget 'near' and 'far'

What are applications of pre-increment and post-increment operators why these operators behaviour are made like this is there any reason for such behaviour?

All operators must return a value, and it is this return value (the evaluation of the operation) that differentiates the pre-increment and post-increment operators. If the return value is of no concern, then the pre-increment operator is the preferred version, particularly when working with objects. This is because the post-increment operator's implementation will generally make a copy of the original object which it will return after incrementing the original object. If the return value is of no concern, then making a copy adds an expensive overhead (this doesn't apply to primitive data types since CPU optimisation can pre-empt the return value without requiring a copy to be made).

Applications for post-increment and pre-increment are many and varied, but ultimately the goal is to increment the value. Whether you use post-increment or pre-increment is largely down to whether you need to use the return value or not, and whether you need to use the original value or the incremented value.

Although the same thing can be achieved with longhand code, it is more efficient to use the appropriate post-increment or pre-increment operators.

For instance:

int x=1;

int y=x;

++x;

Can be implemented more efficiently with:

int x=1;

int y= x++;

Whereas:

int x=1;

++x;

int y=x;

Can be implemented more efficiently with:

int x=1;

int y= ++x;

Use caution when pre-incrementing the same value in a compound statement. For example:

int x=0;

int y= ++x * ++x;

The expected result is 2, but the actual result is 4. This is because both expressions (++x) return the same value: a reference to x. And since x is incremented twice, the expression evaluates to 2*2, not 1*2.

To get the expected result of 2, each operation must be evaluated separately:

int x=0;

int y= ++x;

y*= ++x;

What is relationship between type definition and union and enum?

There is no relationship other than that they are programming concepts. they each serve a different purpose.

Type Definition

A type definition is an alias; an alternate name for a type that already exists. Type definition help to make code easier to read. For instance, instead of using the type "unsigned long long int", we can alias it:

typedef unsigned long long int UINT;

Now we can use the UINT type wherever we would normally have used "unsigned long long int".

Union

A union is a type with two or more members of different types that all have the same start address. The length of a union is determined by the longest member of the union. Unions are useful when you have a variety of data types but do not need to maintain separate values for those types; only one member can be active at any one time. As an example, consider the following:

union pointer {

int* pint;

char* pchar;

};

Here we can assign the memory address of an integer to pint and then read back the first byte of that integer using pchar:

int i=0x12345678;

pointer x;

x.pint = &i;

std::cout<<"Integer: "<<*x.pint<

std::cout<<"Byte: "<<*x.pchar<

The output will be:

Integer: 305419896

Byte: 120

Unions are best avoided as they are often used to provide type-casts that are inherently unsafe.

Enum

An enum is an enumeration. When you define an enumeration you define a type for which some values of that type have names. Those names are constant members of the enum.

enum traffic_light {red, amber, green};

If a type is not specified, the type defaults to an int. Given that there are only three values in this enum, a char would suffice:

enum traffic_light : char {red, amber, green};

Enums are useful in that they allow a related set of constants to be grouped.

If no values are specified, the constants are valued according to the order in which they are declared. Thus the above is equivalent to:

enum traffic_light : char {red=0, amber=1, green=2};

If you assign any value to an enum member, all subsequent members are numbered in sequence:

enum traffic_light : char {red=1, amber, green};

The above is therefore equivalent to:

enum traffic_light : char {red=1, amber=2, green=3};

Enum members can also be given the same value if desired:

enum traffic_light : char {red=1, amber=2, yellow=2, green=3};

Using enums help eliminate coding errors:

void f (traffic_light colour) {/*...*/}

f (red); // ok

f (green); // ok

f (4); // error: 4 is not a member of traffic_light!

Enums are also useful for naming bits:

enum bit {

bit_0 = 1<<0, // = 0x01 = 00000001

bit_1 = 1<<1, // = 0x02 = 00000010

bit_2 = 1<<2, // = 0x04 = 00000100

bit_3 = 1<<3, // = 0x08 = 00001000

bit_4 = 1<<4, // = 0x10 = 00010000

bit_5 = 1<<5, // = 0x20 = 00100000

bit_6 = 1<<6, // = 0x40 = 01000000

bit_7 = 1<<7 // = 0x80 = 10000000

};

void f (bit b)

{

if (b & bit_1)

{

// bit_1 is set in b

}

else

{

// bit_1 is not set in b

}

if (b & (bit_1 | bit_2))

{

// bit_1 and/or bit_2 is set

}

else

{

// neither bit_1 nor bit_2 are set

}

}

Write a function that will scan a character string passed as an argument and convert all lowercase letters onto uppercase letters?

/* Write a function that will scan a character string passed as an argument & convert all lowercase characters into their uppercase characters*/

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<ctype.h>

int str_upp(char c[])

{

int i;

char x;

printf("\n \n");

for(i=0;i<strlen(c);i++)

{

x=toupper(c[i]);

printf("%c",x);

}

return (0);

}

void main()

{

char c[10];

clrscr();

printf("Enter string : \n");

scanf("%s",c);

str_upp(c) ;

getch();

}

/*

Output:

Enter string :

Heloo

HELOO

*/

Need c program for three address code assignment statement?

int x, *px, **ppx, ***pppx;

px = &x;

ppx = &px;

pppx = &ppx;

***pppx= 12345;

What is odd loop?

Move the print out requesting the user to enter an integer outside of the for loop and it will only print once instead of each time around the loop.

You'll need a way to save the even and odd numbers that you detect in the loop.

One way is to have separate arrays to hold the even and the odd numbers as you go around the loop. Then at the end of the loop you can have more loops to print the contents of one array and then the contents of the other array.

Another way is to concatenate the number onto separate Strings (even and odd) to be displayed after the data gathering loop.