Any code in which character values are not restricted to printable characters.
/*
Given two trees, return true if they are
structurally identical.
*/
int sameTree(struct node* a, struct node* b) {
// 1. both empty -> true
if (a==NULL && b==NULL) return(true);
// 2. both non-empty -> compare them
else if (a!=NULL && b!=NULL) {
return(sameTree(a->left, b->left) &&
sameTree(a->right, b->right)
);
}
// 3. one empty, one not -> false
else return(false);
}
What is a prejudicial statement?
Evidence that is admissible if its is inflammatory and will have the effect of biasing jurors.
Write a c program to find number of days in a month using enumerated data types?
#define leap year
void main()
{
enumeratedmonth{jan=1,
feb,
mar,
april,
may,
june,
july,
aug,
sept,
oct,
nov,
dec}
enumeratesd month month;
int day,days,a month
clrscr()
printf("enter no.of month");
scanf("%d",& a month);
switch(a month)
{
case jan:
case mar:
case may:
case aug:
case oct:
case dec:
printf(" no. of day=31"0;
days=31;
break;
case april:
case june:
case sept:
case nov:
days=30;
break;
default;
printf("wrong no.");
day=0;
}
if (day!=0)
printf("no. of days=%d/n",days);
if (a month==feb)
printf("29 if its a leap year");
getch();
}
OOP Features
OOP ideas are supported by default in programming languages like C++ and Java. I'll describe how object-oriented programming, which lacks built-in support in C, can be somewhat adapted to this course.
Class & Objects
First, we create a Human class with characteristics such as his name, gender, and color.
After that, he can build many individuals with varied characters in the earth (things), but all of them can differ in terms of their properties, such as name, gender, and hair color.
God gave me the name Gopi, and I am an instance/object of the class Human. And you are a distinct type of instance/object.
Inheritance
Inheritance occurs when one class incorporates a property from another class.
Inheritance is the process of reusing objects.
Now, God desires that the Human class has properties such as hands, legs, eyes, and so on, as well as functions such as walking, talking, eating, and seeing. However, he is also a made Animal on Earth with the same traits.
Abstraction
"To express the core feature without representing the background details" is the definition of abstraction.
Abstraction allows you to concentrate on what the object does rather than how it does it.
Abstractions supplying pertinent information give you a generic view of your classes or objects.
Abstraction is concealing an object's working style while understandably displaying its information.
Encapsulation
It combines a data member and a method into a single unit (or class).
Encapsulation is the process of encapsulating something in a capsule. That is, confining an object's relevant activities and data within that object.
Encapsulation is similar to a bag in which you can keep your pen, book, and so on. This signifies that the property of encapsulating members and functions is present.
Encapsulation is concealing an object's internal characteristics or how it performs something.
Encapsulation keeps customers from viewing the interior view, where the abstraction's behavior is implemented.
Encapsulation is a technique for protecting an object's information from another object.
Polymorphism
Polymorphism is defined as "one name, multiple forms."
One function behaves in several ways.
Polymorphism is defined as "several forms of a single item."
What is subscript in bluej array?
In BlueJ, as in many programming environments, a subscript refers to the index used to access elements within an array. Arrays in BlueJ are zero-indexed, meaning that the first element is accessed with a subscript of 0, the second with a subscript of 1, and so on. For example, in an array called myArray, myArray[0] refers to the first element, while myArray[2] would access the third element. Using the correct subscript is essential for retrieving or modifying the desired elements in the array.
Difference between declaring a variable and definition a variable?
Declaration is a promise: 'I will define (or has defined) this variable/function somewhere else'.
When does segmentation fault occur for a prog?
You either reference memory that is non existent, or you attempt to modify memory that is read only. This is usually a result of failure to properly initialize or use pointers or arrays.
How do you determine class width?
Not sure what you mean by class width, but if you mean how do you determine the size of a class, the simplest way is to use the sizeof() operator. The value returned may be equal to or greater than the sum of all its member variables, depending on any adjustments made for memory alignment. If the class contains pointers to memory allocated on the heap, this memory will not be included in the total -- only the size of the pointers to those allocations will be considered.
EDIT: Previous answer does not address the question.
#include<stdio.h>
main()
{
int n,m,i,max;
printf("How many numbers(n) you going to enter:");
scanf("%d",&n);
printf("Enter the numbers:");
scanf("%d",&m);
max=m;
for(i=2;i<=n;i++)
{
scanf("%d",&m);
if(m>max)
max=m;
}
printf("The Largest Number is %d",max);
}
Output:
How many numbers(n) you going to enter:5
Enter the numbers:
25
410
362
5
56
The Largest Number is 410
How do you execute c program in terminal?
If you have it compiled and linked, then simply:
$ ./myprogram
if you haven't, then compile and link it first:
$ gcc -g -W -Wall -pedantic -o myprogram myprogram.c(other sources, objects, libraries)
$ ./myprogram
Why gets function gives a warning every time you compile a c program?
It is unsafe. In order to use gets() safely, you need to know how many characters you will be reading to ensure your character buffer is large enough:
char buffer[10];
while (gets (buffer) != 0) { ...process buffer... }
The above code has undefined behaviour when the number of characters read is 10 or more (you need one character for the null-terminator). This is because the character buffer, str, decays to a pointer (referencing &str[0]) and the function, gets(), cannot determine the number of characters in a buffer by its pointer alone.
The gets() function was dropped from the C standard in 2011, however some implementations still include it. To avoid the warning, use the fgets() function instead. This allows you to specify the length of your buffer and (when used correctly) prevents buffer overflow.
char buffer[10];
while (fgets (buffer, 10, stdin) != 0) { ...process buffer... }
How do you do a username and password login program using C-language?
For a username, just get the username from the standard input using scanf and check whether this username matches with the username stored. If it doesn't match, then the username is wrong.
For a password, get each character using getch(). Print a * for each character obtained. Now check this password with the stored password. If these don't match, then the password is wrong.
In real mode far pointers are 32 bit long (segment + offset)
In protected mode 48 bit (16 bit segment + 32 bit offset)
(In 64-bit mode 80 bit (16 nit segment + 64 bit offset) but it's not so useful)
Determine the highest of the three input numbers using flowchart?
(start)
/a=0 c=0\
\b=0 /
/input a/
/input b/
/input c/
/a>b\ no /b>c\ yes /display b/ -> (a)
\ / \ /
yes no
/a>c\ no /display c/ -> (a)
\ /
yes
/display a/
<- (a)
(end)
Does a unary expression consists of only one operand with no operator?
No, a unary expression consists of one operand and one operator
Is missing statement an empty statement that does nothing?
empty statement does nothing, 'missing statement' is an error-message from the compiler, eg: { if (x==2) }
corrected version: { if (x==2); }
How do you convert a List to a Tuple?
It makes no sense to convert a list to a tuple given that tuples are specifically intended for collections of heterogeneous types whilst a list is a collection of homogeneous types. If the intent is simply to reduce memory consumption, then converting the list to an array would achieve the exact same result as converting to a tuple.
Code migration is the movement of programming code from one system to another. There are three distinct levels of code migration with increasing complexity, cost and risk. Simple migration involves the movement from language to a newer version. A second, more complicated level of migration involves moving to a different programming language. Migrating to an entirely new platform or operating system is the most complex type of migration.