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 wildcard characters are represented by?

Your question doesn't really make sense... let's suppose you wanted to ask something else:

Q: What do the wild-card characters represent? A: Question mark represents a single character, an asterisk represents zero or more characters.

Examples: *.c, *example*, foo.?, bar*.???

Why range needed for c data types?

Because each data type uses a certain number of "bits" to store their values, and thus are mathematically limited to the amount of data they can hold before losing information. You can think of an analogy of your mailbox and letters you receive. You can only fit so many letters into the mailbox before it physically cannot hold any more letters.

How do you create a new C source file?

A source file is nothing more than a text file with code. Therefore, any file created in Notepad and saved as "anyname.c" is considered a C source file.

Write a c program which takes two integer operands and one operator from the user performs the operation and then prints the result?

int main() {

int x, y;

char op;

int res;

printf("Enter two numbers and a operator\n");

scanf("%d %d %c", &x, &y, &op);

switch (op) {

case '+':

res = x+y;

break;

case '-':

res = x-y;

break;

case '*':

res = x*y;

break;

case '/':

res = x/y;

break;

default:

printf("Unknown operator %c\n", op);

exit(1);

}

printf("Resault is %d\n", res);

return 0;

}

#include

void math_operations(char operation, int arg1, int arg2);

using std::cout;

using std::cin;

using std::endl;

int main()

{

int num1 = 0;

cout << "Enter first number: ";

cin >> num1;

int num2 = 0;

cout << "Enter second number: ";

cin >> num2;

char operation = '+';

cout << endl << "Enter the operation:"

<< endl << "+ for addition"

<< endl << "- for substruction"

<< endl << "* for multiplication" << endl;

cin >> operation;

cout << endl << "You chose: ";

math_operations(operation, num1, num2);

system("PAUSE");

return 0;

}

void math_operations(char operation, int arg1, int arg2)

{

if (operation '-')

{

cout << "-" << endl;

cout << arg1 << " - " << arg2 << " = " << (arg1 - arg2);

}

else

{

cout << "*" << endl;

cout << arg1 << " * " << arg2 << " = " << (arg1 * arg2);

}

}

* The program was checked in VS2008

How would we write a program that display an equipment color one an input letter match its first letter in turbo c?

#include <stdio.h>

#include <conio.h>

void main()

{

char color;

clrscr();

printf("Enter character (R/G/B): ");

color= getchar();

switch (color)

{

case 'R':

printf ("Red") ;

break;

case 'G':

printf("Green");

break;

case 'B':

printf("Blue");

break;

}

getch();

}

How can I initialize a type that is a pointer to a struct in Go?

For the purpose of clarification, you cannot initialise types, you can only initialise variables (or constants) of a type. A variable (or constant) is known as an "instance" or "object" of the type. All instances of a type must be named. A pointer variable allows us to "refer" to a named object of the pointer's type. this is achieved by storing the memory address (the starting address) of that object. By changing the address stored in the pointer variable, the same pointer variable can be used to refer to different objects in memory. This is useful when passing objects to functions because if we pass objects directly (by name), the function receives a copy of the object. This is known as "pass by value". However, when a function expects a pointer variable rather than a named variable, the address of the object is copied instead. This is known as "pass by reference" and allows the function to operate (indirectly) upon the object being referenced rather than a copy of the object (any changes to a copy are not reflected in the original object).

Passing by reference is particularly useful when the object is large and complex. To improve efficiency, we must avoid making any unnecessary copies of large or complex objects. Functions that do not modify an object are a prime example; there is no point in copying an object that will not be modified. If we wish a function to modify the object, we must pass the object by reference. The only time we should copy an object is when we're not interested in the modifications made by a function, or when we want to compare the changes that were made. In these cases we simply make a copy of the object before passing that copy to the function by reference. When working with concurrency, however, it is best to use pass by value semantics. In this way, each thread works with a local copy of your object, and thus avoids "race conditions", where one task is accessing an object that is being modified by another task, which can lead to unpredictable results.

Pointer variables are said to "point at" the memory the refer to (hence they are called pointers). To access the value being pointed at, the pointer variable must be dereferenced. However, in the case of pointer to struct variables, the dereferencing is transparent.

All variables in Go are implicitly initialised with the default "zero" value for its type. The zero value of a pointer variable is always "nil" (regardless of which type of pointer). You must never dereference a pointer variable that holds the nil value so always check the pointer is non-nil. Equally, you must never dereference a pointer to an object that no longer exists in memory. Always nil your pointers as soon as you are finished with them.

The following example demonstrates how to initialise a pointer variable to a struct:

package main

import "fmt"

type Point struct {

X int

Y int

}

func main () {

v := Point{1, 2} // instantiate an object of type Point

p := &v // assign the address of v to pointer p (p's type is inferred from v)

fmt.Println(*p) // print the indirect value of v (dereference p)

}

Structured programming concepts in c?

Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could lead to "spaghetti code" which is both difficult to follow and to maintain.

Write a program to copy the value of one string variable to another variable?

You can have two String variables (note that String variables are object references) refer to the same String object like so:

String str1 = "Hello";

String str2 = str1;

Now the str1 and str2 are references for the same String object containing the word "Hello".

If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so:

String str3 = new String(str1);

Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello").

Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.

When 25 numbers are entered from the keyboard into an array the number to be searched is entered through the keyboard by user write a program in C to find if number to be searched is present?

#include<stdio.h>

#include<conio.h>

void main()

{

int num[25];

int i,j,k=0;

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

{

printf("Enter numbers : ");

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

}

printf("\nEnter the number to be searched : ");

scanf("%d",&j);

printf("\nthe is %d",j);

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

{

if(num[i]%j==0)

k=k+1;

}

printf("\nIt is repeated %d times."k);

}

Write a c program to implement Ackermann function?

#include<stdio.h>

#include<stdlib.h>

int ack(int,int);

main()

{

int m,n;

printf("Enter the value for m : ");

scanf("%d",&m);

printf("Enter the value for n : ");

scanf("%d",&n);

if(m<n)

printf("The value is : %d\n",ack(m,n));

else

printf("Evaluation is not possible");

}

int ack(int m,int n)

{

int r;

if(m==0)

r=n+1;

else if(m!=0 && n==0)

r=ack(m-1,1);

else

r=ack(m-1,ack(m,n-1));

return r;

}

Sparse matrix Program in c language?

#include
#include
void main()
{
int a[10][10],b[10][3],r,c,s=0,i,j;
clrscr();
printf("\nenter the order of the sparse matrix");
scanf("%d%d",&r,&c);
printf("\nenter the elements in the sparse matrix(mostly zeroes)");
for(i=0;i{
for(j=0;j{
printf("\n%d row and %d column ",i,j);
scanf("%d",&a[i][j]);
if(a[i][j]!=0)
{
b[s][0]=a[i][j];
b[s][1]=i;
b[s][2]=j;
s++;
}
}
}
printf("\nthe sparse matrix is given by");
printf("\n");
for(i=0;i{
for(j=0;j<3;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
getch();
}

What are general characteristics of C language?

The following are the good characteristics of a good program in C language:

  • Always maintain good Indentation.
  • Write comments where ever necessary.
  • Check the program for null inputs.
  • Check the program for garbage inputs.

How do you write 19 in binary numbers?

First let's write it as a sum of powers of two. This will make it easier to write as a binary number.

19=16+2+1

This can be written:

19=16*1+8*0+4*0+2*1+1*1

So the binary form is:

10011

How do you write a program to convert binary code to gray code using c?

Gray code, named after Frank Gray, a Bell Labs researcher who originally called it "reflected binary code", is used to help correct errors in digital communications. It was developed as a response to preventing desynchronized switching actions, requiring only one switch be flipped to increment or decrement a binary value represented by a hardware-based switch array.

The simplest method, without using a whole lot of CPU or brain power, is to create an array of Gray code values that correspond to their binary representation. For example, a 2-bit Gray code array would consist of the following values:

int gray2bit[]={0, 1, 3, 2};

A 3-bit Gray code array would be declared and initialized as follows:

int gray3bit[]={0, 1, 3, 2, 6, 7, 5, 4};

To find the Gray code for a particular value, simply reference that offset in the desired array:

int n=gray2bit[2]; /* results in 3 */

int m=gray3bit[6]; /* results in 5 */

See the related links for more information on Gray codes as well as sample source code that will assist you further.

How many versions of the C language are there?

Between 1969 and 1978, C went through several informal revisions with many implementations from a variety of vendors, including Dennis Ritchie himself, the original author of C. During that period the language was not standardised, so vendors added their own extensions which made it difficult to write portable code.

Brian Kernighan and Dennis Ritchie published the first edition of The C Programming Language in 1978 and this served as an informal standard for C, which became known as K&R C after the authors.

The American National Standards Institute (ANSI) began standardising the language in 1983 which led to the first formal standard, ANSI X3.159-1989 "Programming Language C", informally known as ANSI C, Standard C or C89. The non-portable UNIX C library was handed off to the IEEE working group 1003 which produced the first POSIX standard in 1988.

In 1990, the ISO/IEC JTC1/SC22/WG14 working group for the International Organisation for Standardisation (ISO) adopted ANSI C as ISO/IEC 9899:1990, informally known as C90. Note that C89 and C90 are essentially the same language, the only real difference being some formatting changes.

In 1995, ISO published a revised standard, ISO/IEC 9899/AMD1:1995, informally known as C95, which incorporated Normative Amendement 1 to the C90 standard.

In 1999, ISO revised the standard again with ISO/IEC 9899:1999, informally known as C99.

In 2008, ISO published a Technical Report addressing the use of nonstandard extensions required in embedded C programming.

The current C standard is ISO/IEC 9899:2011, informally known as C11.

Today, most implementers support the C99 standard which is largely compatible with C89. However Microsoft predominantly supports the C89 standard along with those parts of C99 required for compatibility with C++.

What is C used for?

A single letter may have many meanings, but in physics and astronomy, the letter "C" stands for the speed of light, which is 186,000 miles per second.

Write a program to illustrate bitwise operators without swap?

#include<stdio.h> int main() { int n,n2; printf("enter the no. < 15 "); // here i am considering the case of 4 bits. (1111) binary = (15) decimal scanf("%d",&n); n2=n^10; /* 10 = 1010 in binary form, to invert its even bits , we will use bit wise XOR (^) operator 1010 has 1 at its even places, so it will invert the even bits of n. if there is any further problem mail me at buntyhariom@gmail.com www.campusmaniac.com */ printf("\n%d",n2); return 0; }