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 compile time?

Compile Time: In longer form, you might say, "at the time of compiling", or, "when the program is compiled".

When you compile a program, the compiler applies various processes to your source code in order to generate the executable files. These are actions that happen "at compile time".

Other actions happen when you actually run the finished program. These actions are said to occur, at, or in, "run time".

Write a program to extract a portion of a character string and print the extracted string Assume that m?

#include<stdio.h>

#include<string.h>

void main()

{

char str[50];

char ext[50];

int pos,len,i,j=0;

printf("\nenter the main string.....-\n");

gets(str);

printf("\nenter the position and length of the string to be extracted...-\n");

scanf("%d%d",&pos,&len);

for(i=pos-1;i<len+pos;i++)

{

ext[j++]=str[i];

}

puts(ext);

}

/* this is a much easier solution by : ROHIT VERMA*/

Difference between break and goto in C?

The break statement will immediately jump to the end of the current block of code.

The continue statement will skip the rest of the code in the current loop block and will return to the evaluation part of the loop. In a do or while loop, the condition will be tested and the loop will keep executing or exit as necessary. In a for loop, the counting expression (rightmost part of the for loop declaration) will be evaluated and then the condition will be tested.

Example:

#include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf("Hello %d\n", i ); } } #include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf("Hello %d\n", i ); } } #include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf("Hello %d\n", i ); } }

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

if(i == 0) continue;

DoSomeThingWith(i);

}

will not execute DoSomeThingWith for i = 0, but the loop will continue and DoSomeThingWith will be executed for i = 1 to i = 9.

What drug helps to lose weight the fastest?

Eating a healthy, varied diet that is high in fruits and vegetables — including soluble fiber, vitamin D, and probiotics — is the best plan for losing weight from your waistline. Avoiding refined carbohydrates, sugar, and processed foods whenever possible will help you cut calories and get rid of fat more quickly.reduce

How quickly will you lose weight? The volunteers reduced their waist sizes by an average of 1 inch for every 4lb (1.81kg) they lost. So if you lose 1lb (0.45kg) a week you could hope to your waistline by an inch after four weeks. If you are interested to know the amazing secret tips which helps me lose weight fast then click on the link in my bio

How is the main function called in a 'c' language program?

There is no default argument to the main function in C. Every C program must have one (and only one) main function. The standard dictates that the main function may have either of the following definitions:

int main (void) {/*...*/}

int main (int argc, char** argv) {/*...*/}

The first version is used when your program does not require any command-line switches. Note that int main () is an acceptable declaration of the main function in both C and C++, but is not a valid definition in C. Note also that, in C, the return type may be declared void, but not in C++.

The second version is more common. The argc argument holds the count of all arguments in the argv array and is always at least one. The argv argument refers to an array of char pointers to null-terminated character arrays thus all arguments are strings. Thus the value 42 will be passed as the string "42".

The first element, argv[0], is always the fully-qualified path to the program executable (hence argc is always at least one). As well as allowing your program to determine its physical location upon the system, it allows your program to determine its given name even if the user has renamed your executable. This is useful when printing error messages.

Any additional arguments passed from the command-line will be found in elements argv[1] through argv[argc-1]. The final element, argv[argc], is always nullptr.

Write a program using c plus plus to check whether the given square matrix is symmetric or not?

means whether the matrix is same or not

program for symmetric matrix :

include<stdio.h>

#include<conio.h>

main()

{

int a[10][10],at[10][10],k,i,j,m,n;

clrscr();

printf("enter the order of matrix");

scanf("%d %d",&m,&n);

printf("enter the matrix");

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

{

for(j=0;j<n;j++)

scanf("%d",&a[i][j]);

}

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

{

for(j=0;j<n;j++)

at[i][j]=a[j][i];

}

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

{

for(j=0;j<n;j++)

{

if(at[i][j]!=a[i][j])

k=1;

}

}

if(k==1)

printf("not symmetric");

else

printf("symmetric");

getch();

}

Write a c plus plus program that inputs 5 integers from the user and separates the integer into individual digits and prints the digits separated from one another by three spaces each.?

// create an BufferedReader from the standard input stream

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

String currentLine = "";

int total = 0;

int[] ints = new int[5];

// read integers

while (total < 5) {

// get input

System.out.print("Input an integer: ");

currentLine = in.readLine();

// parse as integer

try {

int input = Integer.parseInt(currentLine);

ints[total] = input;

++total;

} catch (final NumberFormatException ex) {

System.out.println("That was not an integer.");

}

}

// print each number

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

// get individual digits

if (ints[i] == 0) {

System.out.println(0);

} else {

while (ints[i] > 0) {

System.out.println(ints[i] % 10);

ints[i] /= 10;

}

}

}

Note that this prints out the digits in reverse order (2048 will print 8 first and 2 last).

What are the applications of array?

arrays are used to store the group of data which are of same type.

These arrays can be applied in student mark sheet applications,online library applications etc.

What are the feature of C language?

An array is simply a contiguous allocation of one or more elements of a given type.

int i; // a single element of type int

int j[100]; // an array of 100 elements of type int

The elements of an array are anonymous (we can't refer to them by name because they have no names). However we can access them by their offset address from the start of the array. The array name serves as a reference to the start of the array and will implicitly convert to a pointer:

int* p = j;

Each element of an array is offset by sizeof (type) bytes. However, the offset is known to the compiler so we do not need to specify it when accessing array elements, we only need to know the zero-based index of the element we wish to access:

int k = j[42];

Note that the suffix operator [] does not perform a range-check. It is up to the programmer to ensure the given index is in range. The array named j has 100 elements so all indices must be in the range 0 through 99. Access beyond the range of an array has undefined behaviour:

int m = j[100]; // undefined behaviour

Given j is a reference, we can also use pointer arithmetic to access elements:

int n = j + 42;

From this we can see that the following holds true:

j[42] 42[j]

It often surprises people to learn that j[42] and 42[j] are equivalent, however it's only because the suffix operator is sugar-coating for the underlying pointer arithmetic so the compiler sees 42 + j, not 42[j]. However, low-level trickery such as this has no place in production code.

The elements of an array are uninitialised at the point of instantiation. However we can use an initialiser to set initial values:

int j[5] = {5, 10, 15, 20, 25};

When we pass arrays to functions, the array implicitly converts to a pointer. This means information is lost in the exchange because the function cannot know how many elements are being referred to by the pointer. Thus we must pass the length of the array as a separate argument:

void f (int* arr, unsigned size) {

for (unsigned idx=0; idx<size; ++idx) {

arr[idx] = 0;

}

}

Given that arrays implicitly convert to pointers, variable-length arrays are treated exactly the same as fixed-length arrays, the only difference is that the programmer is responsible for allocating and releasing the memory:

void g (unsigned size) {

int* p = malloc (size * sizeof (int)); // allocate

f (p, size); // use

free (p); // release

}

Note that variable-length arrays cannot be initialised at the point of instantiation; they must be instantiated then initialised, as shown above.

Fixed-length arrays (where the length is known to the compiler) can be allocated in static memory, on the call stack or on the heap. Global arrays are best allocated statically while small local arrays are best allocated on the stack. Large local arrays should be allocated on the heap. Variable-length arrays must always be allocated on the heap.

How do you write a c program to read two numbers and perform addition and subtraction of two matrices?

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c,n;

printf("enter the numbers");

scanf("%D",&n);

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

a=b;

a=c;

c=a+b;

printf("the sum is %c",);

getch();

}

Why are data structures important?

Data structures are important because they allow us to aggregate different data types and treat them as a single entity. For instance, if we have separate variables such as first name, last name and age to represent a person, embedding them into a data structure means we can handle multiple people much more easily:

typedef struct person {

char* first_name;

char* last_name;

unsigned age;

};

struct person[100] people; // An array of 100 person objects.

Difference between dos and c programming?

Answer: In dos you have to create the complete application, yourself in other words the complete .EXE file, that can be done in any of the many different programming languishes IE. GWBasic, QBasic, C, or ASM etc., the last is the most difficult but the result is the fastest application. Where Windows is a platform for your application, most of the things you want to do is already created in Windows, all you have to do, is to use it from within your application, not that it means less programming, you actually have to do more coding than with Dos, for instance in Dos GWBasic, if you want to read data from a comm. port you just open it as follow

[code]

open "comm1:" for input as #1

input #1, var

close #1

[/code]

But in Windows it is a long story

What is a tree data structure as used in programming?

DATA STRUCTURES AS ITS NAME IMPLIES DATA MEANS "VALUE' AND STRUCTURE MEANS THE WAY IT IS ORGANISED AND THE WAY IT IS ARRANGED INTO MATHEMATICAL AND LOGICAL WAY.

Just like array...array helps you to store elements without declaring multiples variable

eg: num[100] can store 100 variables which are integers. Here if you are not using array and want to store data in 100 variables then you must declare 100 unique variables names. This can be done effectively using data structures.

What is a large array?

one of the world’s largest radio observatories

When is quick sort better than selection sort?

Because the quick sort can be used for large lists but selection not.

selection sort is used to find the minimum element ,but quick choose element called pivot and move all smaller nums before it & larger after it.

Difference Between interpreter and compiler in java application?

Due to platform independence, a Java compiler will interpret Java source code into Java Byte Code and pass to the JVM, which will pass machine understandable code through to cpu. (clarification needed).A conventional compiler converts source code directly to machine code.(clarification needed).

Disadvanatges of object-oriented programming languages?

  • OOP is a more complicated and structured paradigm than, say classic procedural programming.
  • More planning and design is required on the programmer's part.
  • OOP is less efficient in terms of a computer's resources than most other paradigms.
  • OOP is a complex idea - no language including Java and C++ implements it perfectly.
  • OOP may be overkill for smaller, simpler programs.

What is the difference between local and global variable of C language?

4m Sai. Gloabal Variable is variable which is declared before main (). int a=10; main() { } here a is a global variable. where ever u r using this variable ... we'll get the value as 10. Local Variable is a variable which is declared inside the main(). int a=10; main() { int a=5; ........ ....... } here a=5 is a local variable and a=10 is called as global variable. then if u want to get a value... printf("%d",a); then result 'll be a=5; B'cos compiler gives main preference to local variables.. if any local declareation is not there then it 'll prefer global variable.

Character stuffing in C?

#include

#include

main()

{

char a[30],fs[50]="",t[3],sd,ed,x[3],s[3],d[3],y[3];

int i,j,p=0,q=0;

clrscr();

printf("Enter characters to be stuffed : ");

scanf("%s",a);

printf("\nEnter a character that represents starting delimiter : ");

scanf(" %c",&sd);

printf("\nEnter a character that represents ending delimiter : ");

scanf(" %c",&ed);

x[0]=s[0]=s[1]=sd;

x[1]=s[2]='\0';

y[0]=d[0]=d[1]=ed;

d[2]=y[1]='\0';

strcat(fs,x);

for(i=0;i

{

t[0]=a[i];

t[1]='\0';

if(t[0]==sd)

strcat(fs,s);

else

if(t[0]==ed)

strcat(fs,d);

else

strcat(fs,t);

}

strcat(fs,y);

printf("\nAfter stuffing : %s",fs);

getch();

}

Why c is preferred over Java for embedded system?

Embedded systems typically run on extremely limited hardware. Even the smallest implementation of Java (Micro Edition) can't compete with a small C implementation both in terms of memory footprint and execution speed.

What is the extraction operators in C plus plus?

This operator (>>) applied to an input stream is known as extraction operator. It performs an input operation on a stream generally involving some sort of interpretation of the data (like translating a sequence of numerical characters to a value of a given numerical type).

Three groups of member functions and one group of global functions overload this "extraction operator" (>>) applied to istream objects:

  • The first group of member functions are arithmetic extractors. These read characters from the input data, and parse them to interpret them as a value of the specific type of its parameter. The resulting value is stored in the variable passed as parameter.
  • The streambuf version copies as many characters as possible to the stream buffer object used as right-hand parameter, either until an error happens or until there are no more characters to copy.
  • Those in the last group of member functions have a pointer to a function as parameter. These are designed to be used with manipulator functions.

    Manipulator functions are functions specifically designed to be easily used with this operator.

  • The global functions overload the operator when the parameter is either a character or a c-string, and, as expected they extract either one character or a sequence of characters from the input stream.

What is the function of scanner in the microscope?

Document Scanners have a glass plate and a cover. There is also a lamp used to illuminate the document. The scanner moves a mirror, reflecting the light across the document. The light is picked up by a simple CCD camera chip and digitizes the data line by line, like a slow scan TV.

----------------------------------------------------------------------------------------------

Scanners have become an important part of the home office over the last few years. Scanner technology is everywhere and used in many ways:

  • Flatbed scanners, also called desktop scanners, are the most versatile and commonly used scanners. In fact, this article will focus on the technology as it relates to flatbed scanners.
  • Sheet-fed scanners are similar to flatbed scanners except the document is moved and the scan head is immobile. A sheet-fed scanner looks a lot like a small portable printer.
  • Handheld scanners use the same basic technology as a flatbed scanner, but rely on the user to move them instead of a motorized belt. This type of scanner typically does not provide good image quality. However, it can be useful for quickly capturing text.
  • Drum scanners are used by the publishing industry to capture incredibly detailed images. They use a technology called a photomultiplier tube (PMT). In PMT, the document to be scanned is mounted on a glass cylinder. At the center of the cylinder is a sensor that splits light bounced from the document into three beams. Each beam is sent through a color filter into a photomultiplier tube where the light is changed into an electrical signal.

The basic principle of a scanner is to analyze an image and process it in some way. Image and text capture (optical character recognition or OCR) allow you to save information to a file on your computer. You can then alter or enhance the image, print it out or use it on your web page.

----------------------------------------------------------------------------------------------

A scanner is used to scan in printed photographs and other documents so they

can be put into documents or web pages. It uses a light source,

typically a cold cathode lamp to illuminate the scanned imaged. The

light is then reflected off the object and into Charged Coupled Device

(CCD). The Charged Coupled Device collects the information, and through

a series of electronic devices converts the analog signal into a series

of digital signals which can then be read and processed by the internal

electronics of the scanner and subsequently a computer.

----------------------------------------------------------------------------------------------

What do you compile?

Compiling is the act of translating human-readable source code to machine-readable byte code.

In Java, the compiler program is javac