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 delegation in oops concept?

Delegation allows the behavior of an object to be defined in terms of the behavior of another object.

ie, Delegation is alternative to class inheritance. Delegation is a way of making object composition as powerful as inheritance. In delegation, two objects are involved in handling a request: a receiving object delegates operations to its delegate. this is analogous to the child classes sending requests to the parent classes.

Example in a Java/C# like language class A {

void foo() {

this.bar() // "this" is also known under the names "current", "me" and "self" in other languages

}

void bar() {

print("a.bar")

}

}

class B {

private A a; // delegationlink

public B(A a)

{

this.a = a;

}

void foo() {

a.foo() // call foo() on the a-instance

}

void bar() {

print("b.bar")

}

}

a = new A()

b = new B(a) // establish delegation between two objects

Calling b.foo()

will result in a.bar being printed, since class B "delegates" the method foo() to a given object of class A.

WAP to interchange the value of two variable without third variable?

Ellipses (...) used to emulate indentation... swap (int *i1, int *i2) { /* only works for integers, i1 != i2 */

... *i1 = *i1 ^ *i2;

... *i2 = *i1 ^ *i2;

... *i1 = *i1 ^ *i2;

}

What is C program pattern 12321 121 1?

/*determine the pattern 1234321*/

#include<stdio.h>

#include<conio.h>

main()

{

int i, j;

for (i=1; i<=7; i++)

{

if (i<5)

{

j=i;

printf("\n %d", j);

}

else

{

j=8-i;

printf("\n %d", j);

}

}

getch()

}

What is difference between visual c plus plus and mfc?

That is like comparing apples and trees...

Visual C++ is a development environment that allows one to program in C++, which is a language.

MFC (Microsoft Foundation Classes) is a library to allows one to use C++ to write MS Windows programs using a particular set of API-like calls. It is a library, not a language.

The two cannot really be compared, as they are too different in scope.

What is the console operator basic requirement assessment test?

The Console Operator Basic Requirement Assessment Test is designed to evaluate the skills and competencies of individuals seeking positions as console operators, typically in fields like telecommunications or energy management. The test assesses knowledge in areas such as equipment operation, troubleshooting, safety protocols, and communication skills. It aims to ensure that candidates possess the foundational abilities necessary to perform effectively in high-stakes environments. Passing this assessment is often a prerequisite for further training or employment in related roles.

How do you search for an element in unsorted array?

Let's use integers as an example.

int elementToFind; // the element we want to search for

int[] elementArray; // the array we want to search through

boolean found = false; //boolean flag to indicate if we found the element or not

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

if(elementArray[i] == elementToFind) {

// we found the element at index i

// do whatever you want to do with this information

found = true;

}

//if found is still false so it means this element is not found

if(!found) {

//the element is not found in the array

}

}

What is the meaning of statement p z in c-language?

The statement p z in c code is a syntax error. The p is an identifier, and so is the z. They cannot be typed tyogether like that unless an operator is placed between them, such as p + z.

What is a checkout operator?

A checkout operator, often referred to as a cashier, is responsible for processing customer transactions at retail establishments, such as grocery stores or supermarkets. Their primary duties include scanning items, handling payments, issuing receipts, and providing customer service. Checkout operators also play a role in maintaining a clean and organized checkout area and may assist with inventory management or restocking items as needed. Strong interpersonal skills and attention to detail are essential for this role.

How do you use pragma startup preprocessor directive?

Syntax:

==========================================

==========================================

Suppose you want to print a Character for 50 (or so) Times before entering Main ().

Here the code goes:

#include "stdio.h"

#include "conio.h"

void PrintChars ()

{

char cChar;

int iTimes, iLoop;

printf ("\n Enter a Character to print: ");

scanf ("%c", &cChar);

printf ("\n How many times you want \'%c\' to print", cChar);

scanf ("%d", iTimes);

for ( iLoop=1; iLoop <= iTimes; iLoop++)

printf ("%c", cChar);

}

#pragma startup PrintChars

void main ()

{

printf ("Entering Main()...\n");

getch();

printf ("Exit from Main()...\n");

getch();

}

Difference between arrays and linked list?

  • each element in a linked list contains, in addition to data, one or more pointers to other element(s) in the list. such data structures are capable of changing size at runtime according to the needs of the program
  • an array is simply a preallocated block of data elements. once allocated at compile/link time its size can never be changed

Is it true In a sequential search each element is compared to the searchValue and the search stops when the value is found or the end of the array is encountered?

As I know the search method depends on your(programmer's) logic. In sequential search it will be better to stop the search as soon as search value encounters or if search value is not in the array then it should stop at the end.

Find advantage and disadvantage of conditional operator?

I do not think there are disadvantages for conditional operators. Other people will think differently.

Most importantly, what is the answer your teacher want you to give. Read your course material or ask your teacher, is the best advice I can give you.

Implementation of priority Queue using Heap?

  1. Now let's consider how to implement priority queues using a heap. The standard approach is to use an array (or an ArrayList), starting at position 1 (instead of 0), where each item in the array corresponds to one node in the heap:

    • The root of the heap is always in array[1].
    • Its left child is in array[2].
    • Its right child is in array[3].
    • In general, if a node is in array[k], then its left child is in array[k*2], and its right child is in array[k*2 + 1].
    • If a node is in array[k], then its parent is in array[k/2] (using integer division, so that if k is odd, then the result is truncated; e.g., 3/2 = 1).
    Here's an example, showing both the conceptual heap (the binary tree), and its array representation:

    Note that the heap's "shape" property guarantees that there are never any "holes" in the array.

    The operations that create an empty heap and return the size of the heap are quite straightforward; below we discuss the insert and removeMax operations.

    Implementing insertWhen a new value is inserted into a priority queue, we need to:
    • Add the value so that the heap still has the order and shape properties, and
    • Do it efficiently!
    The way to achieve these goals is as follows:
    1. Add the new value at the end of the array; that corresponds to adding it as a new rightmost leaf in the tree (or, if the tree was a complete binary tree, i.e., all leaves were at the same depth d, then that corresponds to adding a new leaf at depth d+1).
    2. Step 1 above ensures that the heap still has the shapeproperty; however, it may not have the order property. We can check that by comparing the new value to the value in its parent. If the parent is smaller, we swap the values, and we continue this check-and-swap procedure up the tree until we find that the order property holds, or we get to the root.
    Here's a series of pictures to illustrate inserting the value 34 into a heap:

How Write a c program to find and replace a string in the given text?

  1. #include
  2. # include
  3. char c1,c2,a[80];
  4. void main()
  5. {
  6. clrscr();
  7. find_rep();
  8. getch();
  9. }
  10. void find_rep(void)
  11. /* Function to find & replace any text */
  12. {
  13. char c1,c2;
  14. char a[80];
  15. int i,j,k;
  16. printf("Enter a line of text below:-");
  17. printf("Press Enter after line..");
  18. printf("You Have Entred:- ");
  19. gets(a);
  20. printf("Enter the replaceable & replacing letter respectively:- ");
  21. scanf("%c %c %c",&c1,' ',&c2); //i have given space & 2nd %c
  22. for (j=0;j<80;j++)
  23. {
  24. if (a[j]==c1)
  25. a[j]=c2;
  26. }
  27. puts(a);
  28. printf("Here all %c are replaced by %c.", c1,c2);
  29. return;
  30. }