AI Programming
12.2K subscribers
713 photos
65 videos
245 files
657 links
An artificial intelligence free resource channel for students, professionals, and anyone who wants to learn how to solve problems.

ENGINEERING πŸŽ– PROGRAMMING πŸŽ– TIPS & HACKS

https://youtube.com/c/AIProgramming
CONTACT US ON: @alphadmin12
Download Telegram
1, #include <iostream>
using namespace std;

int main()
{
const int i = 20;
const int* const ptr = &i;
(*ptr)++;
int j = 15;
ptr = &j;
cout << i;
return 0;
}
Options:
a. 20
b. 21
c. 15
d. Compile error
3. What will be the output of the following program?

#include <iostream>
using namespace std;
int main()
{
int num[5];
int* p;
p = num;
*p = 10;
p++;
*p = 20;
p = &num[2];
*p = 30;
p = num + 3;
*p = 40;
p = num;
*(p + 4) = 50;
for (int i = 0; i < 5; i++)
cout << num[i] << ", ";
return 0;
}
Options:
a. 10, 20, 30, 40, 50
b. 10, 20, 30, 40, 50,
c. compile error
d. runtime error
4. What will be the output of the following program?

#include <iostream>
using namespace std;
int main()
{
int arr[] = { 4, 5, 6, 7 };
int* p = (arr + 1);
cout << *arr + 10;
return 0;
}
Options:
a. 12
b. 15
c. 14
d. error
5 What would be printed from the following C++ program?

#include <iostream>
using namespace std;
int main()
{
int x[5] = { 1, 2, 3, 4, 5 };
// p points to array x
int* p = x;
int i;
// exchange values using pointer
for (i = 0; i < 2; i++) {
int temp = *(p + i);
*(p + i) = *(p + 4 - i);
*(p + 4 - i) = temp;
}
// output the array x
for (i = 0; i < 5; i++)
cout << x[i] << " ";
return 0;
}
a) 5 4 3 2 1
b) 1 2 3 4 5
c)Address of the elements
d) Can’t say
6. What will be the output of the following program?

#include <iostream>
using namespace std;

int main()
{
int a = 32, *ptr = &a;
char ch = 'A', &cho = ch;

cho += a;
*ptr += ch;
cout << a << ", " << ch << endl;
return 0;
}
Options:
a. 32, A
b. 32, a
c. 129, a
d. 129, A
πŸ‘1
7,What would be printed from the following C++ program?

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
float x = 5.999;
float* y, *z;
y = &x;
z = y;
cout << x << ", " << *(&x) << ", " << *y << ", " << *z << "\n";
return 0;
}
a) 5.999, 5.999, 5.999, 5.999
b) 5.999, 5.9, 5.000, 5.900
c) Address of the elements
d) compilation error
8 What would be printed from the following C++ program?

#include <iostream>
using namespace std;

int main()
{
int track[] = { 10, 20, 30, 40 }, *striker;

striker = track;
track[1] += 30;
cout << "Striker>" << *striker << " ";
*striker -= 10;
striker++;
cout << "Next@" << *striker << " ";
striker += 2;
cout << "Last@" << *striker << " ";
cout << "Reset To" << track[0] << " ";

return 0;
}
a) 10, 20, 30, 40
b) Striker>10 Next@50 Last@40 Reset To0
c) Striker>10 Next@40 Last@50 Reset To0
d) Striker> Next@ Last@ Reset To
10 - What is the output of the following program?

#include<iostream>

using namespace std;
main() {
char s[] = "Fine";
*s = 'N';

cout<<s<<endl;
}
A - Fine

B - Nine

C - Compile error

D - Runtime error
2 What is the output of this program?

#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}
a) 2 5 10πŸ‘†
b) 2 4 5✌
c) 2 6 14πŸ‘Œ
d) none of the mentionedπŸ‘
πŸ‘2
3πŸ˜•πŸ˜• #include <iostream>
using namespace std;
void square (int *x)
{
*x = (*x + 1) * (*x);
}
int main ( )
{
int num = 10;
square(&num);
cout << num;
return 0;
}
a) 100
πŸ‘†
b) compile time error
✌
c) 144
πŸ‘Œ
d) 110πŸ‘
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
| C++ Data Structure Exercise 2 |
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
Question. Define a function which increments each elements of the array by 2.

(N.B. The code for the above question and answer posted in picture, now on this post in plaintext)
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
#include <iostream>
using namespace std;
void numinc(int x, int *nums)
{
for(int i=0; i<x; i++){
*nums += 2;
cout<<*nums<<"\n";
nums++;
}
}
int main(){
int num[5]={3,4,5,7,11};
numinc (5, num);
return 0;
}

AI Programming @freecodecs
Have a LitπŸ”₯ Practice Folks πŸ™ŒπŸ½
Stack - Post & Eval.cpp
4.2 KB
Infix to Postfix & Evaluate Using Stack C++
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
Implementation of infix equation/expression to postfix expression converter and evaluator by using stack data structure method.

(N.B. We use stack class from library by calling #include <stack>, which is the same as doing inside our project by declaring function called pop & push.)
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

AI Programming @freecodecs
Have a LitπŸ”₯ Practice Folks πŸ™ŒπŸ½