Reverse a string in C language?
/* To reverse the given string using pointer By $ */
#include <stdio.h>
#include <string.h>
void main ()
{
char str[15];
char rev[15];
int i;
int count;
char* p;
gets(str);
count = strlen(str);
p = rev + strlen(str)-1;
for(i = 0; i < count; i++)
{
*(p - i) = *(str + i);
}
rev[count]='\0';//in some compilers it may show error show u can make it NULL
/* verify results */
printf("Original string: %s\n",str);
printf("Reversed string: %s\n",rev);
}
What is the purpose of a control unit?
A control unit (which is part of the computer processor) directs the flow of information. Think of it like a "traffic guard" if you may- directing traffic so the vehicles go to their destination quickly and safely. This is more or less what a control unit does, it controls where every bit of data goes.
What is the default return type of a function?
The normal exit of program is represented by zero return value. If the code has errors, fault etc., it will be terminated by non-zero value. In C++ language, the main() function can be left without return value. By default, it will return zero.
To learn more about data science please visit- Learnbay.co
A sonometer is a long box with a hook and pulley at opposite ends. Weights are hung on the box, and alternating currents from the AC main is put through the box.
You can use any development system, C or otherwise, to write a text editor. The tool to create one, however, depends upon which environment you want it used under (command-line or graphical).
Assuming you're using the Win32API in one form or another, the CreateWindow() function can be used to create a multiline edit control using the following call:
hwndEdit = CreateWindowEx(0, L"EDIT", NULL,
WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_LEFT|
ES_MULTILINE|ES_AUTOVSCROLL,
x, y, width, height, hwndParent, 0, hInstance, NULL);
This gives you a control with some basic capabilities. Just supply the desired x,y location as well as the width and height. hwndParent is the parent window, and hInstance is the instance your program was given through the WinMain() entry point.
If you're using a modern IDE that allows you to generate forms, you can create a program fairly quickly. Keep in mind that most modern text editors include the following controls:
- a multiline edit box
- main menu (File, Edit, and sometimes Options and Help)
- convenient buttons below the main menu for file and edit operations
Clipboard operations such as copy, cut and paste are also common among text editors. These functions allow you to export and import text data from and to other programs as well as within the text editor.
As with any programming project, start out with the basics and keep adding features you want in the program. Always be sure to conduct bug testing regularly, particularly when you're loading and saving files. Using Notepad as a frame of reference for laying out your controls can come in handy. You may also find some C source code for text editors and base your own on that code.
It's when your loop does not limit where it's suppose to stop, for instance:
...
for (int i(0); i > 0; i++)
{
cout << endl << "Infinite loop";
}
...
How c language convert into machine language?
With a compiler, which is a program that "knows" how to transform the programming language logic in to machine code and make it perform from that.
What is Constructor in C plus plus?
A constructor is a special class method that instantiates an object of the class.
All objects must have at least two constructors, one of which must be a copy constructor. Even if you do not explicitly declare a copy constructor, one is generated for you with public access by the compiler. The purpose of the copy constructor is to instantiate new objects from existing objects. Even if you never explicitly call the copy constructor, it is automatically called whenever you pass an object to a function by value, as the object must be copied.
If you do not declare any constructors, then both the copy constructor and the default constructor are generated for you. The default constructor is a constructor that accepts no parameters, or that is declared with all default parameters.
Although the compiler will generate default and copy constructors for you, it is always recommended that you declare your own constructors, thus ensuring your object members are always correctly initialised and valid. An uninitialised object is a potential time-bomb.
Constructors are not functions; they do not return any value, not even void. The assignment operator (which does return a value) is not a constructor; it is used to initialise an existing object from another existing object -- it does not instantiate a new object.
Constructors are called whenever you instantiate a reference to an object, or allocate memory to an object using the new operator, or copy a new object from an existing object.
All constructors have the same name as the class itself. Construction overloads can be differentiated by their signature (the number and type of parameters they accept). The copy constructor is signified by the fact its only parameter is a constant reference to an object of the same class.
class Object
{
public:
Object(); // Default constructor (no parameters)
Object(const Object& object); // Copy constructor
Object(int x); // Overloaded constructor
}
As well as constructors, it is recommended you also declare your own assignment operator and destructor. Even if the compiler-generated versions are adequate for your needs, it costs nothing but a little time to declare your own. But if your class allocates dynamic memory on the heap, you must include code in the constructors, destructor and assignment operator to ensure that memory is correctly initialised and released, and that self-references are correctly accounted for; the compiler-generated methods will not do it for you.
How do you call function in C?
Every C function has a name so you can easily call any function provided you know its name. However, every function also has identity (a memory address), thus you can also call any function provided you know its address. This is useful as it allows you to pass functions to other functions. This might seem odd since any function can invoke any other function by its given name, however the point of passing functions to functions is that different callers can pass different functions.
For example, consider the following implementation of the insertion sort algorithm:
void insertion_sort (int* arr, size_t size) {
// insertion sort... size_t gap;
int val;
for (size_t idx=1; idx<size; ++idx) {
gap = idx;
val = arr[gap];
while (0<gap && val<arr[gap-1]) {
arr[gap] = arr[gap-1];
--gap;
}
arr[gap] = val;
}
}
Note the comparison operation within the while loop (val<arr[gap-1]) means that this function will always sort the array in ascending order of value. We could include a bool flag in the arguments to be able to choose between ascending and descending order, but this makes our code less than efficient because we now have to repeatedly test the argument in the inner while loop:
void insertion_sort (int* arr, size_t size, bool ascend=true) {
// insertion sort... size_t gap;
int val;
for (size_t idx=1; idx<size; ++idx) {
gap = idx;
val = arr[gap];
while (0<gap && (ascend ? val<arr[gap-1]:val>arr[gap-1])) { <-- INEFFICIENT!
arr[gap] = arr[gap-1];
--gap;
}
arr[gap] = val;
}
}
A better approach is to pass the comparison operator itself. This is achieved by declaring the operator as a function:
bool less_than (int a, int b) { return a<b; }
bool greater_than (int a, int b) {return a>b; }
Note that both functions have the same prototype, they only differ by name. That is, they both accept two integer arguments and they both return a bool. Functions that return a bool are commonly known as predicates.
To create a function pointer we use the following declaration:
bool (*FuncPtr)(int, int);
This declares a function pointer named *FuncPtr that can refer to any function that accepts two integers and returns a bool. Note the function pointer name includes the asterisk. Note also that the parenthesis are required. Without them, the asterisk would bind to the return type instead of the function pointer:
bool *FuncPtr (int, int);
In other words we end up declaring a function named FuncPtr that returns a pointer to bool, which is clearly not what we intended.
We typically use a typedef to avoid the (ugly!) syntax associated with function pointers:
typedef bool (*FuncPtr)(int, int);
Now we have a proper type name (FuncPtr) that we can use in our declarations.
We can now change our sorting function to accept and call the predicate:
void sort (int* arr, size_t size, FuncPtr pred) {
// insertion sort...
size_t gap;
int val;
for (size_t idx=1; idx<size; ++idx) {
gap = idx;
val = arr[gap];
while (0<gap && pred(val, arr[gap-1]) {
arr[gap] = arr[gap-1];
--gap;
}
arr[gap] = val;
}
}
The sorting algorithm can now be invoked as follows:
void f (int* arr, size_t size, bool ascend=true) {
if (ascend) {
sort (arr, size, less_than); // sorts the array in ascending order
} else {
sort (arr, size, greater_than); // sorts the array in descending order
}
}
Or more concisely:
void f (int* arr, size_t size, bool ascend=true) {
sort (arr, size, ascend ? less_than : greater_than);
}
Note that the bool flag is now tested outside of the algorithm and is therefore tested once per call, rather than multiple times within the algorithm itself.
What is the importance of C language?
A C program is basically a collection of functions that are supported by the C library.we can continuously add our own functions to C library.with the availibility of a large number of functions, the programming task becomes simple......
With data structures what are the implementations of using LIFO and FIFO?
Think about what each concept means.
A FIFO (First In, First Out) stack is like a supermarket queue - people are served in the order in which they arrive in line. You'd use a FIFO stack for a process that requires sequential access to data in arrival order, such as transaction processing.
On the other hand, a LIFO (Last In, First Out) stack is like an elevator - the people who board last are nearest the front, so they're the first off in "processing" order. You might use a LIFO stack for something like expression parsing. For example, if you're trying to match up parens, you need to use the "nearest match" rule. That means if you have already stacked two "("s you'd want to pair the most recently-scanned one with the first closing ")" encountered and evaluate the enclosed expression. That means the ")" would pair off with the "(" at the top of your paren stack rather than the bottom; i.e. LIFO.
#include <stdio.h>
#include <conio.h>
int main()
{
int a[10],i,j,temp=0;
printf("Enter all the 10 numbers");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++) //This loop is for total array elements (n)
{
for(j=0;j<9;j++) //this loop is for total combinations (n-1)
{
if(a[j]>a[j+1]) //if the first number is bigger then swap the two numbers
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("The ordered array is");
for(j=0;j<10;j++) //Finally print the ordered array
printf("%d \t",a[j]);
getch();
return 0;
}
Write a program in c plus plus in which insertion and deletion in an array?
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,k,n;
printf("enter number of elements of array");
scanf("%d",n);
printf("Enter array elements");
for(i=1;i<=n;i++)
{
scanf("%d",a[i]);
}
printf("enter the element you want to delete");
scanf("%d",k);
for(j=0;j<n;j++)
{
if(a[j]==k)
{
a[j]=a[j+1];
n=n-1;
}
}
printf("The array after deletion of %d is:",k);
for(i=1;i<n;i++)
{
printf("%d",a[i]);
}
getch();
}
What is the coding of flames program using C Language?
part1:for cancillation of simillar alphabets
#include
#include
#include
int main()
{
int i,j,l,d,count=0;
char a[20],b[20];
clrscr();
printf("enter 2 strings \n");
gets(a);
gets(b);
l=strlen(a);
d=strlen(b);
for(i=0;i { for(j=0;j { if(a[i]==b[j]) { a[i]='\0'; b[j]='\0'; } } } for(i=0;i { if(a[i]!='\0') { count++; printf("%c \t",a[i]); } } printf("\n"); for(j=0;j { if(b[j]!='\0') { count++; printf("%c",b[j]); } } printf("\n count=%d",count); getch(); } part2:for deciding whts the relation is? #include main() { int i,j,k=0,m,count,length; char a[]="flames",b[7],c; clrscr(); printf("enter remaining no. of characters\n"); scanf("%d",&count); length=strlen(a); while(length>1) { for(i=0;a[i]!='\0';i++) { k++; /* printf("k=%d",k); */ if(k==count) { for(m=i+1,j=0;a[m]!='\0';m++,j++) b[j]=a[m]; for(m=0;m b[j]=a[m]; b[j]='\0'; for(m=0;b[m]!='\0';m++) a[m]=b[m]; a[m]='\0'; }/*if*/ if(k==count) {k=0; break; } }/*for*/ length=strlen(a); }/*while*/ /*printf("%s\n",a); */ c=a[0]; switch(c) { case 'f': printf("friends\n"); break; case 'l': printf("lovers\n"); break; case 'a': printf("ansisters\n"); break; case 'm': printf("marriage\n"); break; case 'e': printf("enimies\n"); break; case 's': printf("sisters\n"); break; }/*switch*/ getch();\ } Another model:- #include #include #include void main() { int i,j,str1,str2,count=0,k; char m_name[20],f_name[20],fla[]={"flames"},res; clrscr(); printf("\n enter male name:\n"); gets(m_name); printf("\n enter female name:\n"); gets(f_name); str1=strlen(m_name); str2=strlen(f_name); for(i=0;i { for(j=0;j { if(m_name[i]==f_name[j]) { m_name[i]='\0'; f_name[j]='\0'; } } } printf("\n REMAINING LATTERS:\n"); for(i=0;i { if(m_name[i]!='\0') { count++; printf("%c \t",m_name[i]); } } printf("\n"); for(j=0;j { if(f_name[j]!='\0') { count++; printf("%c \t",f_name[j]); } } printf("\n count=%d\n",count); k=-1; for(i=0;i<5;i++) { for(j=1;j<=count;j++) { k++; if(k>=6) { k=0; } if(fla[k]=='\0') { do { k++; if(k>=6) { k=0; } }while(fla[k]=='\0'); } } fla[k]='\0'; } for(i=0;i<6;i++) { if(fla[i]!='\0') { res=fla[i]; } } switch(res) { case 'f': printf("friends\n"); break; case 'l': printf("lovers\n"); break; case 'a': printf("ansisters\n"); break; case 'm': printf("marriage\n"); break; case 'e': printf("enimies\n"); break; case 's': printf("sisters\n"); break; } getch(); }
What is actual path of execution of a program?
how programs are executed?
Let we take C, how a c program is executing....
A first step we have to install a particular software for a execution so here we are installing turbo c then open the bin folder after the installation ,you will find on executable file named TC.exe it will look like a command prompt that only executing your c program files and giving another executable file for your program as output. to check fisrt create any simple program and first compile it and see the bin folder you will find one file named filename.obj and then run that program and now you will find another file filename.exe,that is an output file.
# Ruby code
print 'Enter n: '; n = gets.to_i
n.times { | i |
puts ( i + 1 ) ** 2 if ( i + 1 ) % 3.0 == 0.0
}
Explain the different searching techniques in c?
In computer science, a search algorithm, broadly speaking, is an algorithm that takes a problem as input and returns a solution to the problem, usually after evaluating a number of possible solutions. Most of the algorithms studied by computer scientists that solve problems are kinds of search algorithms.[citation needed] The set of all possible solutions to a problem is called the search space. Brute-force search, otherwise known as naïve or uninformed, algorithms use the simplest method of the searching through the search space, whereas informed search algorithms use heuristic functions to apply knowledge about the structure of the search space to try to reduce the amount of time spent searching.
Which function calls itself repeatedly?
A main (or not-main) function can return a value to its caller.
If the main function was called by the system, the return value means 0=success other=error-code.
Function main can call itself, but it is not common.
Example:
int main (int argc, char **argv)
{
int rc;
if (argc>1) rc= main (argc-1, argv+1)
else rc= 0;
return rc;
}
When a variable is declared as being a pointer to type void it is known as a generic pointer. Since you cannot have a variable of type void, the pointer will not point to any data and therefore cannot be dereferenced. It is still a pointer though, to use it you just have to cast it to another kind of pointer first. Hence the term Generic pointer.
What is the main purpose of using comments in c plus plus?
The main advantage of the newer C++ comment syntax is that you only need to start the comment, and you can expect that it will last only until the end-of-line. With the older syntax, you needed to also stop the comment. any statement; /* old comment syntax */
any statement; // new comment syntax
What is difference between pointer and structures?
pointer data type that carry address:of data type that has no name but both of them must have same data type.
structures you can make your own data type:
struct name
put any data type you wants
any functions.
How do you write a program to print Armstrong numbers between 1 and 100 using for loop?
/*Program to find Armstrong number between 1 to N*/
int main() {
int n = 0, remainder, sum = 0, i = 0, noDigits = 0, isArm = 0;
char ch[60] = {0};
printf("Find the Arm Strong Numbers between 1 to N");
scanf("%d", &n);
for(i = 1; i<n; i++)
{
isArm = i;
itoa(isArm, ch, 10);
noDigits = strlen(ch);
while(isArm)
{
remainder = isArm%10;
isArm=isArm/10;
sum= sum+pow(remainder, noDigits);
}
if(sum == i)
printf("\nArm Strong Nos are %d\n", i);
sum = noDigits = 0;
}
}